Iran's presidential election was not supposed to be like this - days (and nights) of giddy excitement and political mudslinging and anarchic scenes of a sort that the tightly-controlled Islamic republic has not seen since the revolution.
It was meant to be a formality. The Guardian Council, a body of senior conservative clerics, would select a handful of candidates with impeccable Islamic and revolutionary credentials. The country would go through the motions of democracy to impress the outside world and Mahmoud Ahmadinejad would duly be re-elected, as every other incumbent president has in the republic's 30-year history.
How could the Israel-hating, US-bashing, nuclear weapon-chasing President lose when he was backed by Ayatollah Ali Khamenei, Iran's Supreme Leader, by the Revolutionary Guard and its volunteer Basij militia, by state-controlled television and a nationwide government machine?
The Guardian Council selected three male candidates - a hardline conservative and two relative moderates - to oppose Mr Ahmadinejad, and rejected 470 others, including 42 women. All three were political insiders: Mir Hossein Mousavi was a former prime minister, Mohsen Rezai a former commander of the Revolutionary Guards and Mehdi Karoubi a former parliamentary Speaker.
Then, suddenly, everything spun out of control. Perhaps it was the unprecedented series of six live television debates in which Mr Ahmadinejad and his rivals let loose, hurling charges of corruption, fraud, cronyism and mendacity at each other. The deep rifts between the radical and moderate conservatives in Iran's political elite had never been exposed in this way before.
Perhaps it was Mr Mousavi's daring decision to let his wife, Zahra Rahnavard, defy precedent by actively campaigning for him, and to appear on campaign posters holding her hand. Mr Mousavi is grey and lacklustre, but those actions sent out unmistakable signals to reform-minded women and young people.
Or was it the behind-the-scenes efforts of Hashemi Rafsanjani, the wealthy and powerful President from 1989-97? He was routed by Mr Ahmadinejad in 2005, hates his brand of radical conservatism and clearly has scores to settle. Using Mr Rafsanjani's money and muscle, Mr Mousavi's campaign bypassed the state-controlled media and began to bombard the Ahmadinejad-hating urban middle classes with e-mails and text messages.
Whatever the reason, Mr Mousavi's campaign took off. The youth of Tehran and other cities took to the streets in huge numbers. They flocked to Mousavi rallies in their tens of thousands. They turned the capital into a seething sea of green with their ribbons, headscarves, balloons and bandanas. They festooned the city with posters and banners. Until the small hours of each morning they packed squares, blocked junctions and careered around town in cars with horns blaring and pop music blasting.
The Islamic republic has never seen such sights before. It was almost open rebellion, an explosion of pent-up anger after four years in which the fundamentalist President and his morality police cracked down on dissent, human rights groups, and any dress or behaviour deemed unIslamic. “Death to the dictator,” young men and women roared at Mousavi rallies. “Death to the Government.”
Mr Mousavi is an unlikely champion for such people. He is no reformist. He promises some social and economic liberalisation, and to do away with the hated “morality police”, but he is not challenging the political system. At 68, and distinctly lacking charisma, he is more Bob Dole than Barack Obama. Mousavi-mania is less a reflection of his popularity than of the loathing most educated, urban Iranians feel for a messianic President who has curtailed freedom, embarrassed Iran internationally and squandered record oil revenues through reckless spending.
In 2005 many liberal Iranians refused to vote, partly because they did not want to legitimise a political system that they abhor, and partly because they were profoundly disillusioned at how the conservative establishment had thwarted the reform efforts of their previous champion, President Khatami. But they will turn out in huge numbers today because they cannot contemplate four more years of Mr Ahmadinejad. “Now you and I vote so he will be defeated,” was the text message sent to millions of mobile phones after campaigning ended yesterday.
Iranian democracy, for all its obvious flaws and limitations, suddenly looks vibrant. Against all odds, there has been furious and open debate between the candidates, and a passionate and vociferous public engagement that has eclipsed even the US presidential election last year. The street-level controntations between the two armies of supporters have been astonishingly peaceful, with lots of good-natured banter and scarcely a scuffle.
Who will win is anybody's guess. There are no dependable opinion polls. Mr Mousavi should romp to victory in the big cities, but Mr Ahmadinejad, the self-styled man of the people, still has legions of devoted followers among the poor, the pious and the peasantry. Mr Karoubi and Mr Rezai will, respectively, split the moderate and conservative votes. Mr Mousavi's supporters fear widespread vote-rigging.
Nor is it easy to predict where Iran goes from here. The election has split the ruling Establishment as never before, with its leading members openly trading accusations and insults. It has laid bare the great chasms in Iranian society - traditionalists against modernists, rural against urban, devout against secular. After the insurrection of the past two weeks, after such extraordinary manifestations of popular discontent, it is hard to see how the fractured regime can put the genie back in the bottle.
It is possible that violence will erupt if Mr Ahmadinejad is declared the victor and Mr Mousavi's supporters cry foul. It is likely that Mr Mousavi will fail to meet his supporters' sky-high expectations, partly because the Supreme Leader remains the real power in the land and partly because he is, in truth, a flawed vehicle for their hopes and aspirations.
Only one thing is certain. Iran will never be quite the same again. “We are in a new phase in this country and civilisation,” Saeed Laylaz, a respected political consultant, said as his compatriots prepared to vote.