Iranians head to the polls Friday for a vote that has become a referendum on President Hassan Rouhani's policy of opening up to the world and efforts to rebuild the stagnant economy.
He faces stiff competition from hardline cleric Ebrahim Raisi, 56, who has positioned himself as a defender of the poor and called for a much tougher line with the West.
Rouhani, a 68-year-old moderate cleric, has sought to frame the election as a choice between greater civil liberties and "extremism".
He has pushed the boundaries over the past fortnight, criticising the continued arrest of reformist leaders and activists, and calling on security agencies not to interfere in the vote.
Raisi says he will stick by the 2015 nuclear deal with world powers, that saw curbs to Iran's atomic programme in exchange for sanctions relief, but he points to the continued economic slump as proof that Rouhani's diplomatic efforts have failed.
"Instead of using the capable hands of our youths to resolve problems, they are putting our economy in the hands of foreigners," Raisi said at a final rally in the holy city of Mashhad on Wednesday.
Rouhani responded by calling on voters to keep hardliners away from Iran's delicate diplomatic levers.
"One wrong decision by the president can mean war and a correct decision can mean peace," he said at his own Mashhad rally.
The election comes at a tense moment in US-Iran relations.
Rouhani gained a reprieve on Wednesday when the administration of US President Donald Trump agreed to continue waiving nuclear-related sanctions, keeping the deal on track for now.
But Trump has launched a 90-day review of the accord that could see it abandoned, and is visiting Iran's bitter regional rival Saudi Arabia this weekend.
Supreme leader Ayatollah Ali Khamenei said a massive turnout was needed to show the continued popularity of the Islamic regime.
"Faced with the enemy, the people should show their determination and calm," he said this week.
Despite the global implications, it is the economy that has dominated the campaign.
Rouhani has brought inflation down from around 40 percent when he took over in 2013, but prices are still rising by nine percent a year.
Oil sales have rebounded since the nuclear deal took effect in January 2016, but growth in the rest of the economy has been limited, leaving unemployment at 12.5 percent overall, and almost 30 percent for young people.
Rouhani has vowed to work towards the removal of remaining US sanctions that are stifling trade and investment deals with Europe and Asia, but he is unlikely to receive much assistance from Trump.
Raisi has instead promised to triple cash hand-outs to the poor, hoping to pick up voters that once supported hardline populist Mahmoud Ahmadinejad.
Having proved too independent for the conservative establishment, Ahmadinejad was dramatically barred from standing by the Guardian Council last month as it disqualified all but six of the 1,636 people who signed up for the election.
The presidential race has since narrowed to a two-horse race as the other candidates either pulled out or called on their supporters to back Rouhani or Raisi.
Iranians will also be voting Friday for their local councils, with reformists particularly hoping to undo the conservatives' narrow majority in Tehran.