Now, having stoked his supporters' yearning for change, he faces the harder task of satisfying them without bringing a backlash from the conservatives who still control most of the levers of power.
A pragmatist rather than a gung-ho reformer by nature, Rouhani nevertheless fired up the pro-reform camp with speeches that broke taboos by targeting Iran's hardline elite, from the conservative judiciary to the powerful Revolutionary Guards.
Rouhani openly criticised the human rights record of the authorities, speaking at rallies about "those who cut out tongues and sewed mouths shut". In a debate last week he accused Raisi of seeking to "abuse religion for power".
That drew an unusual rebuke directly from the supreme leader, Ayatollah Ali Khamenei, who called the rhetoric at the debate "unworthy".
Rouhani has decisively defeated Khamenei's protege, hardline judge Ebrahim Raisi. But the supreme leader still makes the ultimate decisions on policy, and his conservative faction still controls the judiciary and security forces.
Rouhani will have to find an accommodation with them, or end up like his reformist predecessor Mohammad Khatami, who whetted Iranians' appetite for change but failed to deliver it during two terms from 1997-2005.
"To appeal to change-seeking voters, Rouhani attacked powerful Iranian institutions ... whose cooperation he will need in order to govern effectively," said Karim Sadjadpour senior fellow at the Carnegie Endowment who focuses on Iran.
Abbas Milani, director of the Iranian Studies program at Stanford University, said: "Rouhani upped the ante in the past ten days in the rhetoric that he used. Clearly it's going to be difficult to back down on some of this stuff."
Rouhani built his reputation as an establishment figure who could deliver some of the aims sought by reformists without alienating conservatives.
"Rouhani is a regime insider. He is loyal to the establishment. He is not a reformist but a bridge between hardliners and reformists," said a former senior official.
Born into a religious family in 1948 and rising to the middle ranks within the Shi'ite clergy, Rouhani was active in the revolution that overthrew the U.S.-backed Shah in 1979. He has held several sensitive jobs in the Islamic Republic, including representing Khamenei for 25 years at the Supreme National Security Council.
When he was swept to office four years ago with three times as many votes as his nearest challenger, Iranians held high hopes that he could fulfil his promises to reduce the country's isolation abroad and bring more freedoms at home.
He promised to heal the wounds of the previous presidential vote in 2009, when mass reformist protests were violently crushed after the disputed the re-election of hardliner Mahmoud Ahmadinejad.
The crowning achievement of Rouhani's first term was a deal with global powers to curb Iran's nuclear programme in return for the lifting of most financial sanctions. Crucially, Rouhani's government won the cautious backing of the hardline supreme leader for the deal.
But since the accord was reached, the promised economic benefits have been slow to arrive. Meanwhile, there was little progress on giving Iranians more freedom at home to gather, communicate and dress as they please.
As his campaign for re-election got under way, many reformist voters said they were disillusioned, an apathy Rouhani's allies saw as the biggest threat to his re-election. His fiery rhetoric in the final days of the campaign was intended to whip up support from reformists and remind them of the high stakes.
(Except for the headline, this story has not been edited by NDTV staff and is published from a syndicated feed.)