Mr Rouhani won 23.5 million votes in the hard-fought contest, compared to 15.8 million for his main rival Ebrahim Raisi.
After his victory, Mr Rouhani vowed to deliver on his campaign promises of creating a freer society and improving the economy.
He wrote on Twitter: “Iran’s great nation. You are the real winners of the election… I shall remain loyal to my commitments to you.”
Although the powers of the elected president are limited by those of unelected Supreme Leader Ayatollah Ali Khamenei who outranks him, the scale of Mr Rouhani’s victory gives the pro-reform camp a strong mandate.
Mr Rouhani, who won 57% to Mr Raisi’s 38% of the vote, was tipped in Iranian media as a potential successor for the 77-year-old supreme leader who has been in power since 1989.
The nuclear agreement Mr Rouhani’s government reached with global powers in 2015, under which most international sanctions have been lifted in return for Iran curbing its nuclear programme, is now likely to remain safe.
The result, which means a second four-year term, also delivers a setback to the Revolutionary Guards, the powerful security force that controls a vast industrial empire in Iran.
However, Mr Rouhani stills faces the same restrictions on his ability to transform Iran that prevented him from delivering substantial social change in his first term and thwarted reform efforts by one of his predecessors, Mohammad Khatami.
The Supreme Leader has the power to veto all policies and ultimate control of the security forces.
The re-elected president will also face the challenge of navigating a tricky relationship with Donald Trump who has dubbed the nuclear agreement signed by former US President Barack Obama as “one of the worst deals ever signed”.
Mr 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 deplore the nuclear deal.
Mr Rouhani,68, campaigned as an ardent reformist to ignite the passions of young, urban voters yearning for change.
He often crossed traditional boundaries by openly attacking the human rights record of the security forces and the judiciary.
At one rally ally he referred to hardliners as “those who cut out tongues and sewed mouths shut”.
Mr Rouhani appeared to have benefited from the big turnout as his backers’ main concern had been apathy among reformist-leaning voters disappointed with the slow pace of change.
Many voters were determined to block the rise of Mr Raisi who was one of four judges who sentenced thousands of political prisoners to death in the 1980s.
Ali Vaez, Iran analyst for the International Crisis Group, a think tank said: “Rouhani’s vote, particularly in rural areas, shows that Iranian people no longer believe in economic populism and radical change.
“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.”
Syrian President Bashar Assad was one of the first world leaders to congratulate President Rouhani on his re-election. The Assad government is strongly backed by Tehran.
He said he congratulated Mr Rouhani on the “confidence that the Iranian people gave to him to go forward in boosting Iran’s status in the region and the world”.
Britain’s Foreign Secretary Boris Johnson also congratulated the president. He said: “During President Rouhani’s first term we made good progress on improving UK-Iran relations, including an upgrade in diplomatic relations, and I welcome his continued commitment to the nuclear deal Iran signed up to in 2015.
“It is important that we now work together to ensure this deal is fully implemented, and its benefits continue to be felt by all parties.”