By Agence France-Presse
With almost all votes counted, Rouhani looked to have an insurmountable lead with 22.8 million votes compared to 15.5 million for his hardline challenger Ebrahim Raisi, election committee chief Ali Asghar Ahmadi announced on state television.
A huge turnout on Friday -- estimated at more than 40 million out of 56 million registered voters -- led to the vote being extended by several hours to deal with long queues.
"I congratulate the great victory of the Iranian nation in creating a huge and memorable epic in the continuation of the path of 'wisdom and hope'," tweeted Vice President Eshaq Jahangiri, referring to the government's slogan.
Rouhani, a 68-year-old moderate cleric who spearheaded a 2015 nuclear deal with world powers, has framed the election as a choice between greater civil liberties and "extremism".
Hardline cleric Raisi, 56, had positioned himself as a defender of the poor and called for a much tougher line with the West.
But his revolutionary rhetoric and efforts to win over working class voters with promises of increased handouts appear to have gained limited traction.
"Rouhani's vote, particularly in rural areas, shows that Iranian people no longer believe in economic populism and radical change," said Ali Vaez, Iran analyst for the International Crisis Group, a think tank.
"They have the maturity to understand that the solution to their country's predicaments are in competent management of the economy and moderation in international relations," Vaez told AFP.
Rouhani's central first-term achievement was a deal with six powers led by the United States that eased crippling economic sanctions in exchange for curbs on Iran's nuclear programme.
He gained a reprieve this week when Washington agreed to continue waiving nuclear-related sanctions, keeping the deal on track for now.
But the election comes at a tense moment in relations with the United States, with President Donald Trump still threatening to abandon the accord and visiting Iran's bitter regional rival Saudi Arabia this weekend.
'Voting to keep that'
Although Rouhani has been deeply entrenched in Iran's security establishment since the early days of the revolution, he has emerged as the standard-bearer for reformists after their movement was decimated in the wake of mass protests in 2009.
"We've entered this election to tell those practising violence and extremism that your era is over," he said during the campaign.
At recent rallies, his supporters chanted the names of reformist leaders under house arrest since 2011 for their part in mass protests two years earlier.
International affairs researcher Foad Izadi, of Tehran University, said Rouhani may now have the leverage to push for more freedoms, despite opposition from the conservative-dominated judiciary and security services.
"A number of years have passed (since the 2009 protests) and the country is demonstrating a high level of stability -- this gives the system confidence, which means more room for change," Izadi said.
But the economy remains the number one challenge.
Although Rouhani brought inflation down from around 40 percent when he took office in 2013, prices are still rising at nine percent a year.
Oil sales have rebounded since the nuclear deal took effect in January last year, but growth in the rest of the economy has been limited, leaving unemployment at 12.5 percent overall, and at almost 30 percent among young people.
"We are still not pleased with the situation, but in the four years of Rouhani there has been a relative improvement and I'm voting to keep that," said Alireza Nikpour, a 40-year-old photographer in Tehran, as he queued to cast his ballot on Friday.
Last month, the Guardian Council excluded all but six candidates for the election but still left a stark choice between moderate-reformists and hardliners.
Two dropped out to back Raisi and Rouhani, respectively, while the remaining candidates -- reformist Mostafa Hashemitaba and conservative Mostafa Mirsalim -- were headed for only a marginal percentage of the votes.