The ignominious exit was the culmination of a chaotic day in which the route of the relay was altered and shortened after thousands of demonstrators – for and against China's hosting of the Olympics – turned out on the city's streets.
It came as the British prime minister's office said Gordon Brown would skip the opening ceremony of the Beijing Olympics, a spokeswoman said.
Brown is the second major world leader after Angela Merkel, the German chancellor, to skip the opening bash but his office said he was not boycotting the Olympics and would attend the closing ceremony.
Modern tradition of torch relay began in 1936 at Berlin Olympics
This year's is the longest ever, travelling 137,000km
The torch will visit 19 nations over 130 days
First destination is Kazakhstan
On the final leg, it will travel throughout China, including Tibet and the summit of Mount Everest
Click here to go to the official torch relay site
(Al Jazeera is not responsible for the content of external websites)
The White House has not ruled out a boycott of the Beijing Games but George Bush, the US president, has said that he will attend the opening ceremony.
On Wednesday Barack Obama, the Democratic presidential candidate, called on Bush to boycott the Olympics if China failed to improve its human rights in Tibet and Darfur.
Last week Democrats in the US congress led by Nancy Pelosi, the House speaker, urged Bush to consider a boycott to protest against China's crackdown on demonstrators in Tibet.
Hours before the San Francisco relay, Bush had urged China to open a dialogue with the Dalai Lama, Tibet's spiritual leader in exile, saying "it would stand the Chinese government in good stead if they would begin a dialogue with the representatives of the Dalai Lama".
In San Francisco, the Olympic torch was drive more than a kilometre away from its planned route, away from China supporters as well as protesters against the Beijing government.
Two runners then carried the torch down a main road flanked by police and Chinese security officials.
Protesters had targeted the route of the torch in London and Paris in the past week over a range of China issues from its recent crackdown on Tibet to human rights.
Beijing has strongly condemned the protests.
Gavin Newsom, the mayor of San Francisco, said the torch route had to be changed at the last minute or the event cancelled to assure public safety.
"It did not appear to be doable with the crowds," Newsom said.
As the ceremony began, the first torchbearer took the flame from a lantern brought to the stage and held it aloft before quickly departing again into a warehouse.
"Flame protection squad" formed in August 2007, tasked with protecting the flame 24 hours a day
Seventy members picked from People's Armed Police, usually responsible for riot control and domestic stability
Training for squad included running 10km a day on mountain roads
Called "thugs" by Sebastian Coe, chairman of the 2012 London Olympics organising committee
Criticised for not knowing how to handle protests and acting as "robots or watchdogs" by David Douillet, a French Olympic official
Blamed for holding up the relay's progress in Paris through procrastination by Pierre Mure, a Paris police official
It then disappeared from public view for about half an hour, while it was driven more than a kilometre inland from its expected location to a main road running through the city.
Officials had already cut the original nearly 10-km route by almost half over fears of protests.
Hundreds of pro-China and pro-Tibet demonstrators blew whistles and waved flags near the site of the relay's opening ceremony.
Police struggled to keep the groups apart and at least one protester was detained
"I think it's cowardly. If they can't run the torch through the city, it means that no one is supporting the Games," said Matt Helmenstine, a California teacher holding a Tibetan flag.
San Francisco is a city with a large Chinese-American population and many had waited to see the torch relay.
Farther along the planned route, about 200 Chinese students reportedly surrounded a car carrying two people waving Tibetan flags.
"In 5,000 years of history the Chinese can finally have one time hosting the Olympics. It means that China is becoming a world power," said Don Zheng, 41, a Chinese-American computer engineer.
Despite the disruptions in London, Paris and San Francisco, the International Olympic Committee says the torch relay will continue despite the continuing protests.