(CNN) -- Say goodbye to Iranian President Mahmoud Ahmadinejad.
In a few weeks, he will hand over the mantle of presidency to Hassan Rouhani, who stood victorious Saturday after Iran tallied all its votes in the national election.
Rouhani, 65, a cleric and moderate politician, who enjoyed reformist backing, took more than 50% of the vote, according to the interior ministry.
His nearest rival, Mohammad Bagher Ghalibaf, the mayor of Tehran, garnered about 15% of the vote.
Three of the six candidates were much more conservative, and the Iranian public viewed Rouhani as a mild alternative going into the vote.
Hawk or dove?
Rouhani has a reputation for avoiding extreme positions and bridging differences, but he is no pushover. He has a long history of service in the country's defense establishment.
He is a former commander of the Iranian air defenses, a leader on three war and defense councils, and was national security adviser to the president for 13 years before Ahmadinejad took office.
Rouhani is also a diplomatic and legal intellectual.
He has three law degrees, including a doctorate from a university in Scotland, and as president of Iran's strategic research center, he regularly publishes essays.
He serves as managing editor for three quarterlies on scientific and strategic research, and foreign policy.
He was also Iran's chief nuclear negotiator from 2003 to 2005 -- during the presidency of Mohammad Khatami , who later became one of the leading figures in Iran's rebellious "Green Movement," which erupted into street protests after the re-election of President Mahmoud Ahmadinejad in 2009.
Ahmadinejad's government violently quashed the protests with the help of elements of a unit of the Revolutionary Guard, which answers to the Ayatollah Ali Khamenei, Iran's supreme leader.
Rouhani has expressed support for the Green Movement. "These were protests that were natural and popular," he has said. "They should have been addressed."
After Green supporters chanted for him at a rally, security forces arrested members of his campaign.
Relationship with Khamenei
Rouhani's relationship with Khamenei has the potential to be complex.
He has represented the supreme leader on Iran's security council since 1989.
But he has purportedly also scrutinized him for being too rigid toward the international community, said Abbas Milani, who runs a research program on Iran at Stanford University.
In a book about his experience as Iran's nuclear negotiator during Khatami's presidency, Rouhani criticizes Ayatollah Khamenei, according to Milani.
"If you read in between the lines, he places a lot of blame on Khamenei. He says in is his book, that if it was up to him, he and his team would have come up with a solution that would not lead up to Iran's case being deferred to the U.N.-- saying 'we could have done this, and some people in Iran and some in the West torpedoed it," Milani said.
A televised presidential debate turned into an animated political clash, which touched on Iran's nuclear program. Exchanges grew so heated that the candidates were later accused of having revealed national secrets during the debate.
Rouhani was warned that he may be barred from running in the elections because of confidential material he revealed about Iran's nuclear program during the two-hour-long debate.
It wasn't his first testy moment with Iran's state-run media. He has openly accused it of censorship and publishing lies.
Many believe Rouhani was not Khamenei's favorite candidate.
Saeed Jalili, Iran's current chief nuclear negotiator, stands more in line with the supreme leader's ultraconservative Islamist views than the moderate president-elect.
But Khamenei has said he is not playing favorites and would not let on whom he voted for.
And Khamenei and his Guardian Council had to approve all candidates before the race began. Out of 680 who applied to run, only eight were allowed to do so. Two later dropped out.
Ultimately, the supreme leader approved Rouhani's candidacy after rejecting the candidacy of a former president, Akbar Hashemi Rafsanjani.
Rafsanjani endorsed Rouhani during his campaign.
Rouhani is a senior cleric and also a member of the Assembly of Experts, which is responsible for appointing or removing the supreme leader. As Khamenei ages and the appointment of a successor becomes necessary, Rouhani will likely have influence on the choice.
Though Ahmadinejad was touted as a hardliner when he entered office, since his re-election, conservative politicians close to the supreme leader have assailed him for being too liberal, and he has often been at odds with Khamenei.
His domestic opponents have been subject to similar caustic accusations his Western foreign opponents have become accustomed to.
Some of Ahmadinejad's associates have faced heavy repression, and hardliners attempted to link the president to the largest embezzlement case in the country's history. Ahmadinejad has hurled allegations of corruption back at them.
Rouhani is more likely to at least speak more diplomatically to internal and external challengers.
And unlike Ahmadinejad, when addressing United States politicians and citizens, he may not need a translator.
CNN's Reza Sayah, Azadeh Ansari, Tara Kangarlou, Mitra Mobasherat and Laura Smith-Spark contributed to this report