TEHRAN // Just weeks after Mahmoud Ahmadinejad's election victory in 2005, Iran's top nuclear negotiator, Hassan Rowhani, stepped down from the post after quarrelsome meetings with the new president.
The decision cemented Mr Rowhani's reputation as a moderate who rejected Mr Ahmadinejad's combative approach in world affairs in favour of the philosophy of Mr Ahmadinejad's leading political foe, the former president Akbar Hashemi Rafsanjani.
Mr Rafsanjani was rejected by Iran's election guardians from Friday's presidential ballot. But for many reformists and liberals in Iran, Mr Rowhani, 64, is somewhat of a mirror image of Mr Rafsanjani by reflecting his outlook that Iran can maintain its nuclear programme and ease tensions with the West at the same time.
Mr Rowhani - the only cleric in the six-candidate presidential field - started religious studies as a teenager. He soon established himself as an outspoken opponent of the Western-backed shah, travelling frequently for anti-monarchy speeches and sermons that caught the attention of Ayatollah Ruhollah Khomeini, the eventual leader of the 1979 Islamic revolution.
In 1972 Mr Rowhani graduated from Tehran University with a law degree. He then went abroad to Glasgow's Caledonian University for a master's degree in legal affairs, according to his campaign biography.
While outside Iran, the stirrings of the Islamic revolution were growing stronger. Mr Rowhani returned to Iran and stepped up his denunciations of the shah but fled the country to avoid arrest.
He then joined Khomeini, who was in self-exile in France, and became part of his inner circle, which included Mr Rafsanjani.
After the revolution, Mr Rowhani rose quickly. He had various roles, which included reorganising the military, serving in the new parliament and overseeing the state broadcaster, which became a valued mouthpiece for Khomeini.
He strengthened his ties to Rafsanjani during the 1980-1988 war with Iraq and, later, as Rafsanjani's top national security adviser during his 1989-1997 terms. Mr Rowhani continued the role with the reformist president Mohammed Khatami, who also appointed Mr Rowhani as the country's first nuclear envoy.
Mr Rowhani took over the nuclear portfolio in 2003, a year after Iran's 20-year-old nuclear programme was revealed. Iran later temporarily suspended all uranium enrichment-related activities to avoid possible sanctions from the United Nations Security Council.
Mr Ahmadinejad strongly opposed any such concessions and deal-making. He also had carry-over friction with Mr Rowhani, who backed his mentor Mr Rafsanjani against Mr Ahmadinejad in the 2005 race.
Mr Rowhani resigned as nuclear negotiator and head of the Supreme National Security Council after a few testy post-election meetings with Mr Ahmadinejad.
During his stops on this campaign, Mr Rowhani had been careful not to directly confront authorities over crackdowns since Mr Ahmadinejad's disputed 2009 election. But Mr Rowhani was seen as clearly siding with Mr Ahmadinejad's reform-minded opponent four years ago, Green Movement leader Mir Hossein Mousavi, who was placed under house arrest in early 2011 along with fellow opposition candidate Mahdi Karroubi.
Taking a page from Mr Mousavi's colour-branded campaign, Mr Rowhani adopted purple for his run for the presidency. That move had consequences with several of his supporters arrested at a rally where the crowd chanted for the release of Mr Mousavi and Mr Karroubi.
At Mr Rowhani's final campaign event earlier this week, chants rang out: "Long live reforms."