Interior Minister Abdolreza Rahmani-Fazli declared Rouhani 's victory on Saturday on state TV, citing figures giving Rouhani about 57 percent of the vote in Friday's election, compared to 38 percent for his main rival, hardline judge Ebrahim Raisi.
Although the powers of the elected president are limited by those of unelected Supreme Leader Ayatollah Ali Khamenei who outranks him, the scale of Rouhani 's victory gives the pro-reform camp a strong mandate to seek the sort of change that hardliners have thwarted for decades.
Rouhani 's opponent Raisi, a protege of Khamenei, had united the conservative faction and had been tipped as a potential successor to the 77-year-old supreme leader. His defeat leaves the conservatives without an obvious flag bearer.
The re-election is likely to safeguard the nuclear agreement Rouhani 's government reached with global powers in 2015, under which most international sanctions have been lifted in return for Iran curbing its nuclear program.
And it delivers a setback to the Revolutionary Guards (IRGC), the powerful security force which controls a vast industrial empire in Iran. They had thrown their support behind Raisi to safeguard their interests.
But Rouhani , 68, faces the same restrictions on his ability to transform Iran that prevented him from delivering substantial social change in his first term, and that thwarted reform efforts by one of his two-term predecessors, Mohammad Khatami.
The supreme leader has veto power over all policies and ultimate control of the security forces. Rouhani has been unable to secure the release of reformist leaders from house arrest. Courts have imposed a ban on the publication of the words -- or even images -- of the earlier reformist president , Khatami.
"The last two decades of presidential elections have been short days of euphoria followed by long years of disillusionment," said Karim Sadjadpour, senior fellow at the Carnegie Endowment who focuses on Iran.
"Democracy in Iran is allowed to bloom only a few days every four years, while autocracy is evergreen."
The re-elected president will also have to navigate a tricky relationship with Washington, which appears at best ambivalent about the nuclear accord agreed by former U.S. president Barack Obama. President Donald Trump has repeatedly described it as "one of the worst deals ever signed", although his administration re-authorized waivers from sanctions this week.
Trump arrived on Saturday in Saudi Arabia, his first stop on the first trip abroad of his presidency. The Saudis are Iran's biggest enemies in the region and are expected to push hard for Trump to turn his back on the nuclear deal.