Millions of Iranians voted for a new president yesterday in an election that was energised by a late surge of support for the sole moderate candidate who is facing a splintered field of hardline hopefuls.
It was the first presidential poll since the disputed contest in 2009 that returned the polarising and provocative Mahmoud Ahmadinejad to power amid allegations of vote-rigging that triggered massive street protests and a ruthless crackdown.
Iran's constitution dictates that Mr Ahmadinejad stand down after his two consecutive and tempestuous four-year terms.
First results are due early today. Unofficial polls indicated none of the six candidates would win a majority, forcing a June 21 run-off among the top two finishers to replace Mahmoud Ahmadinejad, who under the constitution must leave office after his two terms.
His presidency was marked by Iran's growing international isolation and stifling western sanctions against Tehran over its nuclear programme.
At home his tenure was marked by an onslaught against the popular reformist movement and, during his last two years, by his challenge to the overarching authority of Iran's unelected supreme leader, Ayatollah Ali Khamenei.
Yesterday's vote, which took place amid tight security, was being closely watched in western capitals for what effect it could have on deadlocked nuclear negotiations between Iran and six world powers.
Iran's Arabian Gulf neighbours are also monitoring developments, wary of Iran's influence in Iraq and its staunch support for President Bashar Al Assad's regime in Syria.
State television broadcast footage of long queues outside polling stations in Tehran and around the country while the authorities said the 10-hour voting period would be extended because of a "rush of voters".
Just a month ago the election had looked like being a predictable and dull affair, with a loyal and compliant hardliner beholden to Mr Khamenei expected to be a sure winner.
That changed this week when the only reformist candidate dropped out to boost the chances of a moderate cleric, Hassan Rowhani. He won vital endorsements from two popular pro-reform leaders, Mohammad Khatami and Akbar Hashemi Rafsanjani, both former presidents. The latter, a founding father of the Islamic republic and rival of Ayatollah Khamenei, was barred from running.
But all three leading hardline candidates refused to withdraw from the race in favour of one of their number to counter growing support for Mr Rowhani, leaving the result too close to call. Ayatollah Khamenei has not stated his preference for any single candidate.
The first results are due early today. Unofficial polls indicated that none of the six candidates would garner a majority, which would force a June 21 run-off among the top two finishers.
They are likely to be Mr Rowhani, 65, and Mohammad Baqer Qalibaf, the 51-year-old conservative mayor of Tehran, according to official surveys. He is promoting himself as a modernising politician who gets things done and has boasted he could sort out Iran's economy "in less than two years".
Mr Qalibaf has accused Mr Rowhani, a former chief nuclear negotiator, of wanting to make concessions to the West.
The other hardline front-runner is Saeed Jalili, 47, a protégé of Mr Khamenei and Iran's unyielding chief nuclear negotiator who vows to pursue a policy of "resistance" against the West if elected. But his star faded as he came across as dull and uninspiring in three televised debates.
Also in with a chance is Ali Akbar Velayati, Ayatollah Khamenei's veteran foreign policy adviser, who has sharply criticised Mr Jalili's handling of stalled nuclear talks with the West.
"I am standing in line right now to vote. Making up my mind about voting or staying away was a struggle for me," said Shaqayeq, a student in Tehran. "Most reformists have urged us to vote and therefore I decided to vote too. For Rowhani."Mansour Sanatipour, 56, a policeman from the southern port of Bandar Abbas, voting in Dubai, said he too was voting for Mr Rowhani. "He wants to reform the economic and political system, and he will improve Iran's international relations," he said.
Ayatollah Khamenei appeared in tetchy mood as he cast his vote early yesterday. Urging Iran's 50 million eligible voters to turn out in huge numbers to "create a new political epic", he derided western misgivings about the credibility of the election.
"Recently I have heard that a US security official has said that they do not accept this election. OK, the hell with you!" he snapped in remarks broadcast on Iranian state television.
Iranian elections are carefully orchestrated affairs, with candidates vetted by a hardline state body controlled by the Ayatollaj, yet they invariably spring surprises. Mr Khatami was an upset winner in 1997 as was Mr Ahmadinejad in 2005.
Mr Rowhani, originally a long shot, has galvanised disillusioned reformist voters by calling for improved relations with the West, the release of political prisoners and greater media freedoms. Appealing to the huge youth vote, he also vowed to reduce unemployment and to back gender equality.
As he cast his vote, Mr Rowhani declared: "I have come to destroy extremism, and when I see that these extremists are worried by my response and my vote, I am very happy."
Many reformists had considered boycotting the poll because of their bitter experience four years ago when they felt robbed of victory by Mr Ahmadinejad's "stolen" re-election. The two reformist candidates who lost in 2009, Mir Hossein Mousavi and Mehdi Karrubi, have been under strict house arrest for more than two years.
Reformist voters were also dismayed when Mr Rafsanjani was disqualified. But he urged a big turnout to support Mr Rowhani, who is in effect the reformists' default candidate. Other reformist figures also insisted that not voting would only strengthen the hardliners' grip on power.
Outside Iran, votes were cast by the country's huge diaspora in places such as Dubai, Los Angeles and London.
With additional reporting by Reuters