It was only in the last two weeks of the campaign, and possibly the last week, that Rowhani moved into first place with voters. The key moment seemed to be when he gained the endorsement of the two leading reformists from the Iranian establishment.
Rowhani's support barely registered when the election process began, before the Guardian Council had narrowed the field to eight acceptable candidates. Although the latest polls had him in the lead, Rowhani was far short of the 50 per cent-plus level needed to win on the first round.
Two days before the vote, The Washington Post wrote in an editorial that Rowhani "will not be allowed to win."
Rowhani received 51 per cent and now his inauguration is set for Aug. 3.
Supporter of Ayatollah Khomeini since 1960s
In his teens, already a cleric, Rowhani was a supporter of Ayatollah Ruhollah Khomeini, who would lead the revolution that overthrew the Shah in 1979. Rowhani writes in his memoirs that when he was 18, he snuck across the border with Iraq to meet with the exiled leader.
He has known the current Supreme Leader of Iran, Ayatollah Ali Khamenei, as well as the reformist and former president, Ali Akbar Hashemi Rafsanjani, since at least 1967.
He was part of Khomeini's inner circle before they returned to Iran in 1979 and a key player in the leadership ever since. Early on, he held key posts in broadcasting and defence. He was a parliamentarian for 20 years and head of the influential Supreme National Security Council for 16 years, until Mahmoud Ahmadinejad won the presidency in 2005.
He did continue to head the Centre for Strategic Research, as he has done since 1991, and remains the centre's president, reachable by email at email@example.com.
He is said to be fluent in English and several other languages. In the 1990s he earned two degrees from Glasgow Caledonian University in Scotland, including a PhD in 1999, with his thesis entitled "The Flexibility of Shariah (Islamic Law)."
'A quintessential pragmatic conservative'
"We know where he comes from," says Hillary Mann Leverett, co-author of the new book, Going to Tehran: Why the United States must come to terms with the Islamic Republic of Iran.
She describes Rowhani as "a quintessential pragmatic conservative who is capable of making important alliances with reformists and with others."
"That ability to build bridges, to build a coalition, shows that he and the reformists have learned critically important political lessons," she said in an interview with CBC News. Leverett served in both the Clinton and George W. Bush administrations, including as director for Iran, Afghanistan and Persian Gulf Affairs at the National Security Council. She negotiated with the Iranians concerning Afghanistan, al-Qaeda and Iraq.
Of the eight approved presidential candidates, Rowhani was the only cleric and that was important in his garnering support, Leverett argues. She notes that he was able "to garner significant percentages of the vote in the much more traditional, much more religious rural and less cosmopolitan areas of Iran."
Social media played a role
During and after the campaign Rowhani effectively used social media, Mahsa Alimardani, the Research Manager of ASL19 tells CBC News. However, she adds, "at the same time, the conservatives were utilizing social media in quite a savvy way."
ASL19 is dedicated to freedom of expression and freedom of information online and provides anti-censorship tools on the internet. It's based at the University of Toronto.
Judging from the social media traffic ASL19 monitors as well from what friends and family in Tehran are saying, the Toronto-born political science graduate student says there is "definitely an air of jublilance" around Rowhani's win. "Iranians know well how to celebrate things and they're definitely taking this as a victory."
Alimardani says that now there's a chance to reconcile "the very traditional and conservative oligarchy" with Iran's liberal society and especially its youth.
Tweets continue to be sent out from @HassanRouhani, the president-elect's Twitter account. Monday night tweets were sent with links to American mainstream media stories. Earlier in the day, the account live-tweeted his first post-election news conference with English translations.
- Iranian president-elect live tweets his victory
At the presser, Rowhani, in a possible shout-out to U.S. President Barack Obama, said, "This will be a government of hope."
Diplomat sheikh crushed student protests
Rowhani said his government will include politicians from hardline conservatives to reformists. He stuck with current government foreign policy and defended Iran's nuclear program, saying that enrichment will continue but added, "If we see good will we can also take some confidence-building measures."
Long nicknamed the 'diplomat sheikh,' expectations are that in style at least, the sharp edges of the Ahmadinejad regime will be absent under Rowhani.
In a dig at the current government, Rowhani said during a campaign debate, "It is good to have centrifuges running, provided people's lives and livelihoods are also running."
Shaul Bakhash, an Iran expert at George Mason University in Virginia writes that the election result "was a reaffirmation by a majority of Iranians of the desire for a more moderate, more sensible course in both domestic and foreign policy." Bakhash notes that the poor showing of the more conservative candidates was also telling.
- Profiles of the approved presidential candidates
In his analysis, "Rowhani will come to office with something of a popular mandate and commitment to a different set of priorities than have characterized Iranian government policy over the last few years."
However, former Iranian student leader Reza Mohajerinejad told the Wall Street Journal, "If we're ever going to get freedom and democracy … we're not going to get them from Rowhani."
He remembers when Rowhani led a crackdown on a 1999 student pro-democracy protest. After Rowhani called on them to "crush [the protesters] mercilessly and monumentally," security forces "poured into the dorm rooms and murdered students right in front of our eyes," according to Mohajerinejad, who now lives in the U.S.
Victory for reformists
Both Leverett and Alimardani view the result as not only a victory for Rowhani but also a victory for the reformist movement in Iran. A week ago, reformist leader and former president Mohammad Khatami persuaded an even more moderate candidate to drop his candidacy, cementing the reformist support for Rowhani.
The next day Khatami and Rafsanjani, another leading reformist and former president, endorsed Rowhani. From watching the social media traffic, Alimardani says that was a significant game changer, since "Khatami and Rafsanjani carry a lot of weight amongst the Iranian population."
Leverett told CBC News that "It is a victory for the reformists because they have been able to make these kinds of coalitions and compromises."