For Iran's supreme leader, Ayatollah Ali Khamenei, the eight-year presidency of reformist Muhammad Khatami (1997-2005), was a trying time. He resolved to ensure this was to be a one-off episode during his lifetime. That is the key to understanding the events of the past 10 days.

Khatami was committed to expanding the social, cultural and ­political rights of citizens, whereas ­Khamenei wanted to restrict them. When the number of publications more than doubled in the first year of Khatami's presidency, Khamenei used the conservative-inclined parliament to tighten up the press law.

But when the general election of 2000 turned the parliament into a bastion of reformists, with almost two-thirds of the seats, Khamenei's problems multiplied. He resorted to asserting his overweening authority directly to thwart the reformist moves by the two popularly elected institutions.

In June 2005, Khamenei got a chance to block a repeat of his years-long exasperating experience when seven candidates entered the presidential race. Of these, former president Ali Akbar Hashemi Rafsanjani, a pragmatic conservative, was the favourite, followed by the former Speaker Mehdi Karroubi, a moderate reformist, and Mahmoud Ahmadinejad, a hardline mayor of Tehran, with the remaining four contestants trailing far behind.

None of the candidates secured the 50% plus one vote. As expected, Rafsanjani topped the list with 21% of the ballots. But, unexpectedly, the upstart Ahmadinejad trumped Karroubi. He got 19.5% of the vote with Karroubi at 17.5%.

Karroubi cried foul. He alleged that ballot boxes were stuffed in Isfahan, the second largest city, that the Basij militia had illegally campaigned for "one of the candidates" and that Khamenei's son Mujtaba had canvassed for Ahmadinejad.

The supreme leader was livid. He accused Karroubi of "raising tensions" and casting aspersions on the Islamic system. A disappointed Karroubi instantly resigned as an adviser to Khamenei.

As a face-saving device, the guardian council took note of Karroubi's complaint. It claimed that it did a recount in Isfahan – behind closed doors – just as it is doing now. In the end, it certified the election without publishing its findings.

In retrospect, the ballot rigging on a minor scale in 2005 was a dry run for what happened earlier this month – a flagrant exercise which, according to the reformist challenger Mir Hossein Mousavi, was planned "months in advance".

As with vote rigging, so too with repressing street protest. On 7 July 1999, when the parliament, with conservatives forming the largest group, passed the first reading of a bill to tighten up the 1985 press law, adopted during the Iran-Iraq war, students in Tehran protested.

The vigilantes, assisted by security forces, raided Tehran University student dormitories overnight. The protest escalated to other universities in the capital and 16 other cities. As now, so then, the most popular slogan was "Death to dictators" – with some students chanting, "Khamenei haya kon, rahbari to raha kon", Khamanei, have shame, let go leadership. Journalists working for 20 newspapers went on strike.

As now, so then. Khamenei blamed foreign enemies, especially America, for the rioting.

By 13 July, when the street protest had led to 1,400 arrests, the security forces – assisted by the Basij militia, and the vigilante Ansar Hezbollah, patrolling the streets throughout the night – restored law and order.

What has happened this time around is on a much wider scale on all fronts. Since the presidential poll was a nationwide phenomenon, the vote rigging, masterminded by the interior minister, a former campaign manger of Ahmadinejad, was centrally directed.

So too was the popular response and its subsequent suppression by the coercive instruments of the state.

The options for Mousavi were stark: give a clarion call for continued defiant protest, likely to result in the death of hundreds, perhaps thousands, of young lives; or retreat for now to fight another day.

Reformists have lost this battle. But given the demographic makeup of Iran, time is on their side. For an increasing number of voters, the 30-year old Islamic revolution, stuck in its old mould, means less and less by the month.