Iranian voters will decide the fate of moderate President Hassan Rouhani and his policy of engagement with the West on Friday as he goes head-to-head with hardline cleric Ebrahim Raisi.
Rouhani has spent four years trying to pull Iran out of its global isolation, reaching a 2015 deal with world powers that ended some sanctions in exchange for curbs to its nuclear programme.
But with US President Donald Trump threatening to scrap the deal, and visiting Iran's bitter regional rival Saudi Arabia this weekend, that policy of detente looks increasingly in jeopardy.
Raisi has agreed to stick by the nuclear accord but says Rouhani put too much trust in the West.
"We should not show any weakness in the face of the enemy," said the 56-year-old Raisi during a televised debate.
The election has essentially become a two-horse race after the other leading conservative, Tehran mayor Mohammad Bagher Ghalibaf, dropped out on Monday and threw his support behind Raisi.
The field narrowed further on Tuesday when reformist first vice president Eshaq Jahangiri pulled out and endorsed the incumbent.
Rouhani, a 68-year-old cleric, has tried to frame the election as a choice between greater civil liberties and "extremism", and unofficial polls still put him ahead.
But he has faced a much tougher campaign than anyone expected just a couple of months ago, as hardliners have savaged his economic record, saying his diplomatic efforts have done little to tackle poverty and unemployment.
Raisi was a relative unknown when he joined the race earlier this year, having mostly worked behind-the-scenes as a top prosecutor and recently as head of the powerful Imam Reza charitable foundation.
A close ally and former pupil of supreme leader Ayatollah Ali Khamenei, he is seen as the preferred choice of the powerful security establishment, advocating a more self-sufficient "resistance economy" rather than a reliance on foreigners.
Raisi has tried to pick up working-class votes by promising more financial support, as well as playing on his status as a "seyed", or direct descendant of Prophet Mohammed.
Meanwhile, Rouhani says he needs more time to rebuild the economy, which was shattered by years of sanctions and mismanagement when he took over in 2013.
"At the halfway point, we don't turn back," he tells voters.
He has vowed to work towards removing the remaining, non-nuclear sanctions imposed by the US, which have strangled Iran's efforts to sign trade deals with European and Asian countries.
That would be a tall order, given that Trump has launched a 90-day review to see whether he will stick by the nuclear deal at all, let alone remove any other sanctions.
While Iranians largely welcomed the reduced tensions with the West, the ongoing economic slump has taken a toll on morale.
"My cheques keep bouncing," said Babak, a 35-year-old clothing supplier in south Tehran. "I may vote, but I know it doesn't change anything."
Unemployment is officially stuck at 12.5 percent -- close to 30 percent for the young -- and many more are under-employed or struggling to get by.
Rouhani says he inherited a financial mess from his populist predecessor Mahmoud Ahmadinejad, who was dramatically barred from standing this year by the Guardian Council after falling foul of the conservative establishment.
That has left a vacuum for many working-class voters who fondly recall the construction boom, cash hand-outs and earthy rhetoric of Ahmadinejad's rule.
Voter apathy is a threat to the Islamic regime, which stakes its legitimacy on a high turnout every four years.
"The regime needs participation. What matters most is the turnout, not the result," said Clement Therme, of the International Institute for Strategic Studies.
Nonetheless, many voters, particularly wealthier urbanites, are attracted to Rouhani's promise of greater social freedoms.
At his last major rally in Tehran, thousands chanted for reformist leaders locked up after mass protests in 2009.
Rouhani has made thinly veiled references to Raisi's past as a prosecutor during a period in the 1980s when many dissidents were executed.
"The people of Iran shall once again announce that they don't approve of those who only called for executions and jail throughout the last 38 years," he said recently, referring to the 1979 revolution.
"We've entered this election to tell those practising violence and extremism that your era is over."