By Roger Hardy
BBC Middle East Analyst
The role of the Supreme Leader is at the heart of the political crisis
How are we to understand the tumultuous events in Iran over the last few weeks?
In the 30 years since the Islamic revolution which overthrew the Shah, there has been no shortage of rows, crises and factional squabbles.
But this time is different. This time the disputes are out in the open - and the stakes could not be higher.
There is a sense that Iran is at a crossroads.
At the heart of the current crisis is the role of the Supreme Leader. This is the office created by the revolution's founding father, Ayatollah Khomeini.
It put him at the top of the pyramid of political power, giving him the final say in all important decisions.
But since Khomeini's death in 1989, the office has been held by Ayatollah Ali Khamenei, who lacks the charisma and religious authority of his revered predecessor.
It was Ayatollah Khamenei's intervention in June's presidential elections that plunged the country into turmoil.
By endorsing the conservative candidate, Mahmoud Ahmadinejad, as the winner, he abandoned the Supreme Leader's traditional neutrality as a figure above the political fray.
"The office has been de-legitimised," says Iranian political scientist Farideh Farhi of the University of Hawaii, "because the Leader has chosen to take sides - and has come out in support of a violent approach to demonstrators."
So, given that the stakes were so high, why did the Leader act as he did?
Barbara Slavin of the Washington Times is the author of a book on US-Iranian relations.
Although there are plenty of conspiracy theories, she says, it is possible that the answer is hubris.
After 20 years in the office, power went to the Leader's head - and he overreached.
Besides, she points out, Ayatollah Khamenei - like many other Iranians - genuinely believed that, at a time of tension between Iran and the West, the country needed a strong president rather than some "lily-livered reformist".
Enough is enough
Thousands protested against what they said was a rigged election
But whatever the Leader's calculations, it was a costly mistake.
Endorsing Mr Ahmadinejad as president for a second term, after what many saw as a fraudulent election, provoked protest on an unprecedented scale.
It also left the regime more dependent than ever on two paramilitary forces - the Revolutionary Guard and the volunteer militia known as the Basij.
Many clerics are appalled.
In their eyes, says Jon Alterman of the Washington think-tank, the Centre for Strategic and International Studies, the point of Islamic government is to lead the public - not to beat the public.
He thinks some clerics may now be inclined to say, "Enough with one man being Leader. We'll have three, we'll have a committee. The Leader will advise, the Leader won't rule."
That would pitch the Islamic Republic into uncharted waters.
But it is an option that seems to be favoured by one of the key figures in the power struggle - the former President Akbar Hashemi Rafsanjani.
Salvaging the system?
Mr Ahmadinejad is due to be sworn into office again in August
During the elections, Mr Rafsanjani supported the main reformist candidate, Mir Hossein Mousavi - and was clearly shocked when Mr Ahmadinejad was declared the winner.
Speaking at Friday prayers at Tehran University on 12 July, he presented himself as a loyal supporter of the system whose duty was to rescue it from crisis and division.
It must have been a difficult decision, says political scientist Farideh Farhi, but he decided to say openly that the leadership had taken the wrong path.
"What he's trying to do," says journalist Barbara Slavin, "is somehow salvage the system in a way that retains some figment of legitimacy - and that's not going to be easy."
Mr Rafsanjani has had a chequered career. He has come under fire because of his great wealth and because of the human rights abuses which tarnished his presidency in the 1990s.
It would be ironic, says Ms Slavin, if this was his legacy - to preserve the legitimacy of the regime and at the same time rehabilitate his own rather tattered reputation.
Whether that is possible must be an open question.
With Mr Ahmadinejad due to be sworn in for a second term on 5 August, the government has a tough choice.
If it makes concessions in the face of continuing demonstrations, that would be a humiliating climb down.
If, as seems more likely, it clings to power, it will do so as a wounded regime whose credibility is ebbing away.