It was unclear when the final count would be known. Iran has more than 50 million eligible voters, and turnout in Friday's election was believed to be high.
Many reform-minded Iranians who have faced years of crackdowns looked to Rowhani's rising fortunes as a chance to claw back a bit of ground.
While Iran's presidential elections offer a window into the political pecking orders and security grip inside the country - particularly since the chaos from a disputed outcome in 2009 - they lack the drama of truly high stakes as the country's ruling clerics and their military guardians remain the ultimate powers.
Election officials began the ballot count after voters waited on line for hours in wilting heat at some polling stations in downtown Tehran and other cities, while others cast ballots across the vast country from desert outposts to Gulf seaports and nomad pastures. Voting was extended by five hours to meet demand, but also as possible political stagecraft to showcase the participation.
The apparent strong turnout - estimated at 75 percent by the hardline newspaper Kayhan - suggested liberals and others abandoned a planned boycott as the election was transformed into a showdown across the Islamic Republic's political divide.
On one side were hard-liners looking to cement their control behind candidates such as Jalili, who says he is "100 percent" against detente with Iran's foes, or Qalibaf.
Opposing them were reformists and others rallying behind the "purple wave" campaign of Rowhani, the lone relative moderate left in the race.
Mortazavi said Rowhani had more than 834,000 votes from the 1,819,984 counted so far. Qalibaf trailed with more than 320,000, and Jalili had more than 257,000. The other three candidates were further back.
But even if the last-moment surge around Rowhani brings him to the presidency, it would be more of a limited victory than a deep shake-up. Iran's establishment - a tight alliance of the ruling clerics and the ultra-powerful Revolutionary Guard - still holds all the effective power and sets the agenda on all major decisions such as Iran's nuclear program and its dealings with the West.
Security forces also are in firm control after waves of arrests and relentless pressures since the last presidential election in 2009, which unleashed massive protests over claims the outcome was rigged to keep the combative Mahmoud Ahmadinejad in power for a second and final term. He is barred from seeking a third consecutive run.
The greater comfort level by the theocracy and Revolutionary Guard sets a different tone this time. Opposition groups appear too intimidated and fragmented to revive street demonstrations, and even a win by Rowhani - the only cleric in the race - would not likely be perceived as a threat to the ruling structure.
Rowhani led the influential Supreme National Security Council and was given the highly sensitive nuclear envoy role in 2003, a year after Iran's 20-year-old atomic program was revealed.
"Rowhani is not an outsider and any gains by him do not mean the system is weak or that there are serious cracks," said Rasool Nafisi, an Iranian affairs analyst at Strayer University in Virginia.
"The ruling system has made sure that no one on the ballot is going to shake things up."
Yet a Rowhani victory would not be entirely without significance either. It would make room for more moderate voices in Iranian political dialogue and display their resilience. It also would bring onto the world stage an Iranian president who has publicly endorsed more outreach rather than bombast toward the West.
The last campaign events for Rowhani carried chants that had been bottled up for years.
Some supporters called for the release of political prisoners including opposition leaders Mir Hossein Mousavi and Mahdi Karroubi, both candidates in 2009 and now under house arrest. "Long live reforms," some cried at Rowhani's last rally.