Moderate cleric Hassan Rouhani has been declared the winner of Iran's presidential vote.
The surge behind Mr Rouhani, a former nuclear negotiator, was seen by his supports as a rebuke of uncompromising policies that have left Iran increasingly isolated and under biting sanctions from the West over the country's nuclear programme.
The ruling clerics barred from the race reform candidates seen as too prominent, allowing a list of hopefuls who were mainly staunch loyalists of the supreme leader and the Islamic establishment.
But the opposition settled on 64-year-old Mr Rouhani as the least objectionable of the bunch, making him a de facto reform candidate with backers inspired by his message of outreach rather than confrontation.
Celebrations broke out across Tehran and other cities. Thousands of Mr Rouhani's supporters took to the streets leading to his campaign headquarters in Tehran before the final results were announced, despite a statement from Mr Rouhani urging his supporters to avoid street gatherings.
There were no reports of unrest or attempts by security forces to rein in the crowds, another sign of the sweeping scope of Mr Rouhani's victory with more than three times as many votes as his nearest rival.
Outgoing president Mahmoud Ahmadinejad congratulated Mr Rouhani. He said: "I hope ... opportunity will be provided more than before to serve and work for the establishment of justice and development of the country."
Mr Rouhani won with 50.7% of the more than 36 million votes cast, the Interior Ministry reported, well ahead of Tehran Mayor Mohammad Bagher Qalibaf with about 16.5%.
Hard-line nuclear negotiator Saeed Jalili - who said he was "100%" against detente with Iran's foes - came in third with 11.3%, followed by conservative Mohsen Rezaei with 10.6%.
Interior Minister Mostafa Mohammad Najjar said the turnout was 72.7%. Iran has more than 50 million eligible voters.