Sir Keir was taken away by car near Parliament shortly after 17:00 GMT on Monday, having been surrounded by a group of demonstrators.
A man and a woman were arrested after a traffic cone was thrown at officers, the Metropolitan Police said.
Several politicians have raised concerns over safety.
Labour has not commented - but it is understood Sir Keir returned safely back to his office and was not harmed during the incident.
In a tweet, Prime Minister Boris Johnson condemned the "absolutely disgraceful" behaviour directed at Sir Keir and thanked police for "responding swiftly".
"All forms of harassment of our elected representatives are completely unacceptable," Mr Johnson wrote.
Videos on social media showed Sir Keir being escorted into the police car on the Victoria Embankment, opposite the London Eye.
Protesters can be heard repeatedly shouting "traitor", while criticising the Labour leader for backing Covid vaccinations and not "opposing the government".
Some protesters were seen holding signs opposing mandatory vaccinations and restrictions to curb the spread of Covid.
One person shouted: "Do you enjoy working for the new world order?"
On one of the videos, someone can be heard shouting: "Jimmy Savile."
Mr Johnson has been heavily criticised for making a false claim that Sir Keir failed to prosecute serial sex offender Savile when he was director of public prosecutions.
The prime minister made the remark in parliament last Monday as he was grilled by MPs over the findings of an interim report on Downing Street parties held during Covid restrictions.
Mr Johnson sought to clarify his remarks last week, insisting the Labour leader "had nothing to do personally" with the decision not to prosecute Savile.
"I was making a point about his responsibility for the organisation as a whole," Mr Johnson said.
Some Conservative MPs have urged Mr Johnson to apologise and last week his former head of policy, Munira Mirza, cited the comment as the reason for resignation.
The Labour leader has previously described the comment as "a ridiculous slur, peddled by right-wing trolls".
When asked whether he would like to see an apology on Monday, Sir Keir said it was "up to the prime minister how he conducts himself".
BBC political editor Laura Kuenssberg said the incident was an ugly reminder of the conditions politicians sometimes face from small but angry bands of protesters on all different issues.
But, she said, for Downing Street on Monday night, it will have "reignited the row inside the Tory party about the prime minister's original claims" over Sir Keir and Savile.
"It's made this another torrid night after a very, very bumpy week for the prime minister, just at the point when No 10 had very much hoped to move on," she added.
After the incident at Westminster, Labour London Mayor Sadiq Khan tweeted: "This is what happens when fake news is amplified and given credibility by people who should know better."
And Conservative MP Julian Smith tweeted: "What happened to Keir Starmer tonight outside Parliament is appalling. It is really important for our democracy & for his security that the false Savile slurs made against him are withdrawn in full."
Another Conservative MP, Sir Roger Gale, echoed those sentiments and said he feared the "disgraceful treatment" of Sir Keir was "the direct result of the deliberately careless use of language" in the House of Commons.
Home Secretary Priti Patel said she was in contact with police regarding the scenes outside Parliament, which she said were "completely unacceptable".
"All Members of Parliament must be able to go about their lives without fear of threats or intimidation," Ms Patel wrote in a tweet.
Analysis by Shayan Sardarizadeh, BBC Monitoring
Today's protest in Westminster was an attempt to replicate the "freedom convoy" in Canada's capital in recent days.
But unlike the protest in Ottawa, the UK rally was small. Familiar faces from anti-vaccine rallies that have been held during the pandemic were in attendance.
The small gathering outside the headquarters of the Metropolitan Police had been relatively quiet up until Sir Keir was surrounded.
Amid shouts of "traitor" and references to Jimmy Savile and paedophiles, the Labour leader was accused by one protester of "ignoring our Magna Carta".
This a familiar theme used by followers of the so-called "sovereign citizen" movement.
They believe they can opt out of laws - including Covid restrictions - by invoking a clause in Magna Carta - the royal charter of rights signed in 1215.
They have handed fake legal documents to health workers and teachers to try to stop Covid vaccinations and some have even tried to remove Covid patients from intensive care wards, citing non-existent "common law" empowering them to do so.
Monday's incident happened as Sir Keir walked from the Ministry of Defence along the Victoria Embankment towards Portcullis House, part of the Palace of Westminster, with shadow foreign secretary David Lammy.
Mr Lammy, Labour MP for Tottenham, tweeted to say he had been harassed alongside Sir Keir and thanked police for helping him "get me safely back to Parliament".
"Intimidation, harassment and lies have no place in our democracy," Mr Lammy tweeted.
The Met issued a statement saying: "Shortly after 5.10pm on Monday, 7 February, a man who had been surrounded by a group of protesters near to New Scotland Yard, was taken away from the scene by a police car.
"A man and a woman were arrested at the scene for assault of an emergency worker after a traffic cone was thrown at a police officer. They have been taken into custody."