With two days to go before it chooses its next mayor, America's quintessential bastion of liberalism is in ferment. A massive grass-roots campaign is under way to try to unseat the incumbent, Willie Brown, one of the wiliest politicians in the country now engaged in the political fight of his life.
The administration is mired in corruption scandals and accusations of dirty machine politics. The underside of San Francisco society - the working class, the homeless, the struggling Latino and African-American minorities - are in revolt against what they see as an attempt to push them out of the city altogether.
Everywhere there is anger at the arrogance of the new masters of the internet revolution, the "dot.com" economy that is pushing San Francisco's rents into the stratosphere and transforming its once funky, individualistic neighbourhoods into sanitised playgrounds for the corporate elite.
In short, San Francisco is being racked by a profound identity crisis as it considers the price of its success as a beacon for the internet age. The new hi-tech companies which have flooded into the city - the "Multimedia Gulch" that has sprung up in the warehouses and tenements in the South of Market and Mission districts - have brought in extraordinary new wealth, as have the Silicon Valley geeks turning to San Francisco as their dormitory community of choice. But they have also challenged the very core of the city's sense of self.
Until this election, the process seemed inevitable. The money rolled in, neighbourhood after neighbourhood gentrified, and Mayor Brown, a consummate deal-maker long before he came to San Francisco in 1995, lorded over the proceedings with almost unseemly relish. Although he was far from popular - the city perpetually complained about the dysfunctional bus system and his piecemeal elimination of low-rent housing - his re-election looked a near-certainty thanks to his mastery of the Democratic Party machine and the mediocrity of his two visible challengers.
But then the city woke up. Just weeks before the first round of voting in November, a handful of influential liberals began leaning on the only senior figure capable of representing their views with any credibility, the president of San Francisco's Board of Supervisors, Tom Ammiano. A former stand-up comic with a long teaching career, as well as a prominent place in the gay community, he had already considered running but ruled it out for lack of financial backing.
Then he changed his mind. It was way too late to have his name printed on the ballot, much less raise any serious campaigning funds. But his supporters doggedly spread the word door-to-door, set up a makeshift headquarters in a juice bar in the Castro district and taught thousands how to write "Ammiano" onto the voting form without invalidating it.
Such a flood of "write-in" ballots came in that the vote count took several days to complete. Mr Ammiano came in second, good enough to make Tuesday's run-off. What might have been just another electoral contest between two guys in suits heated up into something altogether more compelling.
The Great Schism, one newspaper called it. A choice between conformity and radicalism, between the dynamics of the marketplace and the dynamism of the street. "This is the last chance to save San Francisco," intoned Laurel Wellman of the San Francisco Weekly. "Save it from the chain stores, from the corporations, from the big money that throws ordinary people out on to the street." Despite such protestations, the election is not about ideology: rather, it is about leadership style.
Mr Brown is an old-fashioned politician who has applied the principles learned in 15 years as speaker of the California state assembly: building a power base through relentless networking and cronyism. Mr Ammiano, by contrast, believes in a purer form of democracy.
Mayor Brown wears sharp Italian suits, travels by limousine and revels in his own imperial demeanour. Mr Ammiano wears corduroy jackets and takes the bus. Mayor Brown has carefully cultivated select minority groups around the city, notably gays and African Americans (he is himself black); Mr Ammiano's supporters accuse him of simply buying off chunks of the electorate.
Beyond the acrimony, it is a striking testimony to modern San Francisco's maturity that this election pits a black man against a homosexual, without either fact being cause for undue fuss. Despite the city's tolerant reputation, it is only 20 years since San Francisco's first openly gay public official, Harvey Milk, was murdered by a homophobic colleague. These days, such rage is more likely to be directed towards the young dot.commer with multimillion dollar stock options talking too loud on his cell phone. That, surely, is progress of a kind.