Gavin Newsom has been elected mayor of San Francisco in a victory likely to cheer the Democrats in California.
The Democrats were scared of losing the San Francisco seat
Mr Newsom beat stiff competition from Green Party candidate Matt Gonzalez.
The race pitted two of the city's youngest and most dynamic politicians against each other to replace Willie Brown, the outgoing mayor.
The election was viewed as a referendum on the Democrats' strength in California after they lost the state governorship to the Republicans.
Same but different
Mr Newsom, who started the race with an estimated lead of 20percentage points, captured 53% of the vote compared to Mr Gonzalez's 47%.
Both candidates attracted as much attention for their youth and good looks as for their policies on issues such as housing development.
But they differed in their supporters.
Wealthy Mr Newsom was tied to the city's big business and property owners. Mr Gonzalez, a lawyer, had the support of artists, social activists and many who lived in rented homes.
And for the campaign, Mr Newsom was able to raise $4m, nearly ten times as much as Mr Gonzalez.
But even with his minimal campaign funds, Mr Gonzalez's Green Party gave the Democrats a scare.
The Green party was a threat to the Democrats
The Democrats have controlled San Francisco city hall for more than four decades and the city is crucial to the party's national strength.
But after losing the governor's seat to Republican actor-turned- politician Arnold Schwarzenegger, Democrats worried about losing San Francisco to the Green party.
So when Mr Newsom's campaign had appeared to waver, top Democrats were called in, including former president, Bill Clinton.
Among other things, Mr Newsom is expected to take a tough line on the homeless and the city's police department, which has one of the country's poorest records in solving crime.