"You, the great Iranian nation, are the victor of the election", Rouhani said on his Twitter account in his first comment after winning the vote on Saturday.
Rouhani won Friday's presidential election by securing an absolute majority of the votes.
Into last months of his first term, Rouhani has a tough time ahead to mend strained relations with the Arab world and Turkey.
Vice President Eshagh Jahangiri, who briefly contested the presidency before dropping out and supporting Rouhani, tweeted congratulations to Rouhani and all Iranians for the "gigantic victory". More than 40 million out of 56 million eligible voters cast their ballots.
Because Iran's two-term presidents are often lame ducks, it's not uncommon for the political system they operate in - especially the portions subject to election - to turn its attention to the next election and undermine the president's interests to suit its own.
As the results of the Iran vote were announced, Trump was beginning his first foreign trip as US president, arriving in Saudi Arabia.
But the deal has serious opponents in the United States, where President Donald Trump and the Congress are reviewing their options.
Rouhani has come to embody more liberal and reform-minded Iranians' hopes for greater freedoms and openness at home, and better relations with the outside world. The Saudis are Iran's biggest rivals, blaming Tehran for fomenting unrest and war in Syria, Iraq and Yemen, and are vehemently opposed to the nuclear deal.
His nearest challenger was hard-line cleric Ebrahim Raisi, with 15.5 million votes.
Global 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.
"Today is the golden page in the history of the Islamic Republic of Iran", Rouhani's interior minister, Abdolreza Rahmani Fazli, said in televised remarks.
Rouhani had won 21.6 million votes, compared to 14 million for Raisi, with 37 million votes counted, the source added. "The Iranian nation has chosen the path of interaction with the world, a path which is distant from extremism and violence", Rouhani said in first speech after his victory was announced. Others wore green, representing the reformist movement crushed by security forces after a 2009 election and whose leaders have been under house arrest since 2011.