Moderate cleric Hassan Rowhani, bolstered by a late surge in support from reformists, led the race on Saturday to succeed Mahmoud Ahmadinejad as Iran's president, initial election results showed.
Rowhani, a former top nuclear negotiator, had secured 51 percent of the votes at 65 percent of polling stations by early afternoon, the interior ministry said.
He had 11,754,013 votes of the 23,014,873 ballots counted by 3:30 pm (1100 GMT), it said, adding that his nearest rival, conservative Tehran Mayor Mohammad Baqer Qalibaf, collected 15.18 percent of the votes.
Under Iranian law, the first-round winner must clear a threshold of 50 percent plus one vote to avoid a run-off against the second-placed candidate.
If there is a second round it will be on June 21.
Whoever wins will inherit an economy mired in crisis and harsh sanctions imposed by the United Nations and several Western and European nations over Iran's controversial nuclear programme.
Friday's election was the first since the 2009 disputed re-election of Ahmadinejad triggered massive street protests by supporters of his rivals, that were crushed by a deadly crackdown.
More than 50.5 million Iranians were eligible to vote for a successor to Ahmadinejad, who after two consecutive terms was constitutionally barred from standing this time.
Voters turned out in force on Friday, with Rowhani benefiting from the withdrawal earlier of the only reformist candidate, Mohammad Reza Aref.
The former first vice president pulled out on Tuesday at the urging of reformist ex-president Mohammad Khatami, who then threw his weight behind the 64-year-old Rowhani.
In 2003, when Rowhani's was top nuclear negotiator under Khatami, the Islamic republic agreed to suspend its controversial enrichment of uranium.
The programme was restarted two years later when Ahmadinejad became president.
Iran has been at loggerheads with world powers over its nuclear drive, which the West suspects is aimed at developing atomic weapons.
Signup to our newsletter and follow us on Facebook and Twitter!
Tehran denies the charge, but the resulting sanctions because of the stand-off has isolated it internationally.
In campaigning, Rowhani pledged to move to ease those sanctions, which have led to severe economic pain.
Inflation is raging at more than 30 percent, the rial has lost nearly 70 percent of its value, and unemployment is rising.
The economy formed the focus of voters' concerns.
"We expect the new president to improve the economy so that it gets better and better," said Tehran resident Farshid Hassan Zade.
In the counted so far, Rowhani and Qalibaf are followed by former Revolutionary Guards chief Mohsen Rezai with 11.83 percent and top nuclear negotiator Saeed Jalili with 11.26 percent.
Conservatives Jalili, Qalibaf and ex-foreign minister Ali Akbar Velayati (6.10 percent so far) are all considered close to supreme leader Ayatollah Ali Khamenei.
Rowhani, who also boasts of close ties with moderate ex-president Akbar Hashemi Rafsanjani, also touts his relations with Khamenei, who has the final say on all key issues, including the nuclear programme.
Rowhani is a representative of Khamenei on the Supreme National Security Council, Iran's top security body, where he was also its secretary for 16 years until 2005.
In the run-up to Ahmadinejad's disputed 2009 re-election, official election results were quickly released. But this time the count has taken far longer.
Interior Minister Mostafa Mohammad Najjar said on Saturday his electoral staff would not "compromise accuracy for speed".
Abbas Ali Kadkhodaei, spokesman for the Guardians Council electoral watchdog, said "no violation" had been reported.
However Ahmed Shaheed, the UN Special Rapporteur on human rights on Iran, said on Thursday that the political climate in Iran did not allow a "free and fair" election.
Tehran resident Ali Yousefi said after voting on Friday: "I think that there was a great level of participation in this election which shows that people will show up when they should and turn everything to their favour."
The 2009 protests that followed Ahmadinejad's re-election led to the eventual detention under house arrest of Mir Hossein Mousavi and Mehdi Karroubi, and the widespread suppression of reformists.
The surge in support for Rowhani came after Khatami publicly endorsed him, asking all his supporters to vote for him.
Khatami's endorsement also gave birth to an online movement, with social networkers urging abstentionists not to waste their votes.
Many Internet users adopted as their profile picture Rowhani's official colour purple, and his symbol of a key to open the door to solutions to Iran's problems.