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.