Interior Minister Mostafa Mohammad-Najjar announced on state television that Rowhani secured just over 50 percent of the ballot based on a 72 percent turnout of 50 million eligible voters.
"Mr Hassan Rowhani got the absolute majority of votes and was elected as president," Najjar said.
The outcome will not soon transform Iran's long tense relations with the West, call into question its disputed pursuit of nuclear power or lessen its support of Syria's president in the civil war there - matters of national security that remain the domain of Supreme Leader Ayatollah Ali Khamenei.
But the president runs the economy and wields important influence in decision-making and Rowhani's meteoric rise could offer latitude for a thaw in Iran's foreign relations and more social freedoms at home after eight years of confrontation and repression under hardline President Mahmoud Ahmadinejad, who was legally barred from seeking a third consecutive term.
Though an establishment figure, Rowhani is a former chief nuclear negotiator known for his nuanced, conciliatory approach. He has pledged to promote a policy of "constructive interaction with the world" and to enact a domestic "civil rights charter".
Rowhani's wide margin revealed a broad reservoir of pro-reform sentiment with many voters, undaunted by restrictions on candidate choice and campaign rallies, seizing the chance to repudiate the dominant hardline elite over Iran's economic woes, international isolation and crackdowns on social freedoms.
In an apparent move to convey political continuity to both domestic opponents and Western adversaries, Khamenei said that whatever the result of Friday's election, it would be a vote of confidence in the 34-year-old Islamic Republic.
"A vote for any of these candidates is a vote for the Islamic Republic and a vote of confidence in the system," the top Shi'ite cleric's official Twitter account said.
Iran's rial strengthened about 4 percent against the U.S. dollar on Saturday after partial vote tallies pointed to a resounding Rowhani victory, web sites tracking the currency said. Celebratory crowds assembled near Rowhani's headquarters in downtown Tehran a few hours before his victory was confirmed.
"Long live reform, long live Rowhani," a reporter at the scene quoted the crowds as chanting.
"Ahmadi, bye bye," the crowds chanted in a reference to Ahmadinejad, another witness there told Reuters.
At the last presidential election in 2009, the jubilation of crowds sensing a reformist victory in Tehran turned to shock and anger after results showed Ahmadinejad had won, a result opposition leaders said was rigged.
Security forces crushed the protests and authorities insisted the result was fair.
Iranian authorities and the candidates themselves, including Rowhani, discouraged large street rallies this time round to forestall any possible flare-up of violent instability in the sprawling OPEC member state of 75 million people.
Rowhani's nearest rival was conservative Tehran Mayor Mohammad Baqer Qalibaf, a long way behind with less than 16%. Other hardline candidates close to Khamenei, including current nuclear negotiator Saeed Jalili, scored even lower.
"Strong patriot, tough, but fair"
British former Foreign Secretary Jack Straw, who dealt with Rowhani during nuclear negotiations between 2003 and 2005, called him a "very experienced diplomat and politician".
"What this huge vote of confidence in Doctor Rowhani appears to show is a hunger by the Iranian people to break away from the arid and self-defeating approach of the past and for more constructive relations with the West," he said before Rowhani's victory was declared.
"On a personal level I found him warm and engaging. He is a strong Iranian patriot and he was tough, but fair to deal with and always on top of his brief."
Suzanne Maloney, senior fellow at the Brookings Institution, speaking before the interior ministry announcement, said Iran "appears to be on the verge of shocking the world".
Rowhani's campaign was endorsed by pragmatic former president Akbar Hashemi Rafsanjani after the latter was barred from running by a state vetting body - out of concern, analysts said, that he could prove too potent a rival to Khamenei.
Rowhani received another big lift when reformists led by ex-president Mohammad Khatami swung behind him after their own lacklustre candidate Mohammad Reza Aref withdrew to help consolidate the non-conservative vote.
In contrast, several high-profile conservatives with close ties to powerful clergy and Revolutionary Guards chiefs failed to unite behind a single candidate, suffering what appeared to be a decisive split in their support base as a result.
Rowhani came to prominence as Iran's nuclear negotiator in talks with Britain, France and Germany between 2003 and 2005 that Tehran Iran agree to suspend uranium enrichment-related activities, easing Western pressure on Tehran.
He left the post when Ahmadinejad came to office in 2005. Enrichment work resumed and there has been virtually no progress in intermittent talks since then.
The result has been a punishing expansion of international sanctions against Tehran, seriously damaging its heavily oil-dependent economy.
Rowhani would be an important bridge between hardliners around Khamenei who reject any accommodation with the West and reformers muzzled for the last four years who argue that the Islamic Republic needs to be more pragmatic in its relations with the world and modernise at home in order to survive.