Iranian voters enter a polling station for the presidential and municipal councils elections in Tehran, Iran, Friday, May 19, 2017.
Voters stand in a queue to cast their ballots during the presidential election in a Jewish and Christian district in the center of Tehran, Iran, May 19, 2017. But in the aftermath this boiled over into the biggest public protests since the 1979 Iranian Revolution that paved the way for the Islamic republic. Rouhani and the suave Javad Zarif, the foreign minister in the outgoing government, showed how there was space to manoeuvre, despite the all-encompassing and powerful office of the Supreme Leader.
The presidential race has since narrowed to a two-horse race as other candidates either pulled out or called on their supporters to back Rouhani or Raisi. "The supreme leader is paving the ground for his succession", he said, "while a frustrated Iranian youth is seeking jobs and a move away from crisis to normalcy".
Rouhani, who struck a deal with world powers two years ago to curb Iran's nuclear programme in return for the lifting of economic sanctions, said the election was important "for Iran's future role in the region and the world". That accord was done with Khamenei's blessing. This time, too, there could be a similar result, since only two strong candidates remain in the fray. If reelected, however, he will face a more confrontational Trump administration, which has taken a harsh line against Iran and placed the nuclear deal under review. The Iranian economy is yet to see a flood of foreign investments, which were projected to come in after the easing of the sanctions.
His main opponent is the 57-yeay old Ebrahim Raisi, a conservative, often tipped to be the next Supreme Leader, Ali Khamenei, and a staunch critic of the nuclear deal.
Raisi, a law professor and former prosecutor who heads an influential religious charitable foundation with vast business holdings, is seen by many as close to Khamenei.
Rouhani is good at co-opting the message of greater social and political freedom on the campaign trail, according to Suzanne Maloney at Brookings. It was widely believed that a low turnout would favor Raisi because he is favored by Iran's security forces, who could mobilize support for him.
Meanwhile, Raisi has promised to triple cash handouts to the poor, hoping to pick up voters who once supported Rouhani's populist predecessor Mahmoud Ahmadinejad. Raisi has made a name for allegedly being involved in the execution of political prisoners in the 1980s.
Any Iranian 18 or older can vote in Friday's election.
Across Asia, Europe and the Americas, Iranian expatriates cast their ballots in various countries but Canada did not allow Iran to set up polling stations on its territory. They dip one of their index fingers in ink, making a print on the form, while officials stamp their ID so they can't vote twice.
Polls had initially been slated to close at 6 p.m., but were extended until 8 p.m.to accommodate "a rush of voters".
Still, the election offer stark choices for Iranians on the direction of their country.
The conservative-dominated Guardian Council must validate the results of election.
If Rouhani loses, there are fears of a repeat of 2009, when a disputed election led to months of unrest and bloodshed. Turnout for presidential elections is generally high.
At one Rouhani rally last week, where the crowd was mostly young and cosmopolitan, many said they were there to take a stand.
Be proactive - Use the "Flag as Inappropriate" link at the upper right corner of each comment to let us know of abusive posts.
Follow Jon Gambrell on Twitter at www.twitter.com/jongambrellap. If you would like to discuss another topic, look for a relevant article.
Be Civil - It's OK to have a difference in opinion but there's no need to be a jerk.