The most important turning point in the life of Grand Ayatollah Hussein Ali Montazeri came in the late 1980s, when the authorities in Iran brusquely ordered his picture taken down from mosques and government offices.
At that moment he ceased being the designated successor to the Iranian ruler Ayatollah Ruhollah Khomeini and instead became persona non grata with the revolutionary regime.
The relationship between the two had been particularly close: Montazeri had been the pupil of Khomeini, who had fondly described him as "the fruit of my life." But after Khomeini took charge of the new Islamic republic he found to his dismay and displeasure that Montazeri was not in the business of offering automatic obedience, and indeed criticised aspects of his rule.
As a result Montazeri incurred Khomeini's wrath, and was abruptly demoted from hero to zero. That in effect opened the most interesting period of Montazeri's life, since he became one of the regime's most outspoken internal critics.
He remained an insistently dissident voice until his death, at the age of 82, denying the legitimacy of this year's re-election of Mahmoud Ahmadinejad as president of Iran. He bluntly declared that "no one in their right mind" would believe the election results.
Montazeri's attack on the regime could hardly have been fiercer: he condemned it as "a political system based on force, oppression, changing people's votes, killing, arresting and using Stalinist and medieval torture."
The authorities in Teheran must surely have been relieved at the departure of such a trenchant critic who had for two decades been a thorn in their flesh. He was born in 1922 into a peasant family which farmed in Najafabad in Isfahan in what was then Persia. He received theological training both in Isfahan and at the religious centre of Qom.
In Qom he studied under Khomeini, coming to admire both his religious erudition and his politics. He went on to become a teacher at a theological school, but in 1974 his opposition to the Shah of Persia earned him a four-year prison term.
He emerged from jail in 1978 to play an active role in the revolution which the following year saw the Shah flee into exile. Khomeini, who had been in exile, returned in triumph to take power with Montazeri as a valued lieutenant. In 1985 he was formally nominated as Khomeini's successor, being given prestigious offices and positions. Khomeini's photograph in government offices was generally accompanied by a smaller image of Montazeri.
Khomeini wrote to him: "All of the people know that you are the harvest of what I have sown during my life. The people must follow you."
But it all went wrong between the two men when Montazeri began to exhibit what Khomeini viewed as an excess of independence. The two had their philosophical differences about how an Islamic state should be run, but it was Khomeini's actions which Montazeri found objectionable.
Montazeri called for more open policies, endorsing human rights, the legalisation of political parties and better treatment for those in prison. it is said that the torture he himself experienced in the Shah's prisons left him with strong feelings about the welfare of inmates.
But the Iran of the ayatollahs could hardly have meted out worse treatment to prisoners, for Khomeini hanged thousands of them, often without proof or fair trials. Montazeri protested against Khomeini's onslaught in which up to 20,000 may have died, on gallows which could despatch up to 20 people at a time.
Montazeri pulled no rhetorical punches. Criticising the fatwa issued against Salman Rushdie, for example, he declared that "people around the world are getting the idea that our business in Iran is murdering people."
Khomeini, furious, announced that Montazeri had resigned and suddenly there were no more photographs of him and no more respectful references to him, or articles by him, in the state media. His title of Grand Ayatollah was withdrawn; his sayings disappeared from school textbooks; streets named after him quickly acquired new names. One moment he was revered as a particularly scholarly cleric and the nation's next leader: next he was lampooned him as a simpleton.
When Khomeini died in 1989, to be replaced by Ali Khamenei, Montazeri made it clear that he continued to disapprove of the regime. In 1997 Khamenei had him placed under house arrest in Qom, which lasted for five years, for criticising his authority. Khamenei, uneasily aware that this own religious credentials were no match for those of Montazeri, who had the status of "source of emulation", regarded him as a menace. When a prosecuted dissident praised Montazeri from the dock the court had him gagged.
Montazeri, interviewed by The Independent's Robert Fisk while under house arrest, complained: "I was one of the mouthpieces of the revolution. But when they treat me like this, how must they be treating the others?"
He accused conservative clergy of creating groups "who used violence and attacked people when they wanted to speak publicly. And they attacked me too. These kinds of action make people hate religion. But you can never serve the interests of religion through violence."
Fisk concluded after the interview: "He might turn out, in retrospect, to be the greatest hero of the Iranian revolution, the man who stood by his word, the man who protested in the greatest tradition of all humanitarians against the ferocious executions of Khomeini's opponents and who refused, always, to bow to his oppressors."
This year's disputed elections resulted in a stream of strident condemnations from Montazeri, who warned that the handling of mass protests by a government which he took to calling a dictatorship "could lead to the fall of the regime." Only a few weeks ago he declared that the militia used to put down opposition rallies was forsaking the "path of God" for the "path of Satan".
Many thousands attended his funeral. In a statement after his death Khamenei said coolly: "In the later part of his life there was an ordeal that I wish Almighty God will forgive and conceal, and that his worldly suffering will be atonement for that."
He is survived by his wife, two sons and four daughters.
Hussein Ali Montazeri, theologian and politician: born Najafabad, Iran 1922: married (two sons, four daughters); died Qom, Iran 19 December 2009.