Hardline cleric Ebrahim Raisi, a harsh critic of the West and the standard bearer of Iran's security hawks, has drawn on economic discontent to mount an unexpectedly strong challenge to pragmatist Hassan Rouhani in Friday's presidential elections.
A protege of Supreme Leader Ayatollah Ali Khamenei, Raisi has focused his campaign on the economy, visiting rural areas and small villages, promising the poor housing, jobs and more welfare benefits.
"I represent laborers, women without guardians, those who have a lot to say but have no microphone," the 56-year-old cleric said in a televised presidential debate.
Iranian media have speculated that he could go even further than the presidency as a possible successor to his patron Khamenei, the 77-year-old who has been in power since 1989 and whose authority exceeds that of the elected president.
Raisi has promised to create six million jobs in his first term if elected, and to triple monthly cash handouts to the lower class. Rouhani's allies call such promises "populist" and say Raisi has not explained how he will pay for them.
Reformists and rights activists also say they are alarmed by Raisi's background as a hardline judge, especially during the 1980s when he was one of four judges that imposed death penalties on thousands of political prisoners.
In the tense final televised debate, Rouhani stretched the boundaries of permissible rhetoric in Iran to paint Raisi as a power-hungry pawn of the security services.
"Mr. Raisi, you can slander me as much you wish. As a judge of the clerical court, you can even issue an arrest order. But please don't abuse religion for power," Rouhani said at one point. He said "security and revolutionary groups" were busing people to Raisi's rallies, and asked who financed them.
But Raisi's economic message could win traction with voters who have seen few benefits so far from Rouhani's signature achievement, a deal with world powers to curb Iran's nuclear program in return for lifting financial sanctions.
Raisi says the president sold out Iran's interests too cheaply to the West, betting too strongly on rapprochement with enemies while doing too little at home to boost production.
"Our problems cannot be resolved by Americans and Westerners," Raisi said in September before announcing his candidacy. "They have not resolved a single problem of any country. They have brought nothing but misery to other nations."
However, Raisi has said he will abide by the nuclear deal and will guard it "regardless of its many faults."
"The nuclear deal is like a cheque that Rouhani's government was not able to cash," he said in a television interview.
Raisi is a mid-ranking figure in the hierarchy of Iran's Shi'ite Muslim clergy but has been a senior official for decades in the judiciary which enforces clerical control of the country.
Last year Khamenei named him custodian of Astan Qods Razavi, an organization in charge of a multi-billion-dollar religious foundation that manages donations to the country's holiest shrine in the northern city of Mashhad.
The religious conglomerate, whose economic arm lists 36 subsidiary companies and institutes on its website, owns mines, textile factories, a pharmaceutical plant and even a major oil and gas firm.
Even before the revolution, "those who led this endowment were very close to the head of state, to the supreme power of the country," a former senior Iranian diplomat told Reuters on condition of anonymity. "Raisi has lots of power."
Raisi studied Islamic law under Khamenei and is widely seen as a protege of the supreme leader, who is nominally expected to remain neutral in electoral politics.
"Raisi is in Khamenei's circle of trust. He has been one of Khamenei's students and his thoughts are very close to the Supreme Leader's," reformist former lawmaker Jamileh Kadivar told Reuters.
Raisi's representatives have denied that Khamenei told himto run. However, rival conservatives who might have split the anti-Rouhani vote have stepped aside to give Raisi a clear shot under pressure from allies of the supreme leader.
The most recent candidate to back Raisi was the popular mayor of Tehran, Mohammad Baqer Qalibaf, who dropped out of the race on Monday. Now, campaign posters show the black-turbaned Raisi alongside Qalibaf in a yellow safety helmet, trying to appeal both to religious groups and pragmatists.
Although he had little public profile before this election cycle, Raisi is a veteran of the upper reaches of the Iranian power structures. He served as deputy head of the judiciary for ten years, before being appointed prosecutor-general in 2014.
"Raisi knows his way in the dark corridors of Iranian politics very well. But he is more used to grilling politicians in the comfortable shade of the judiciary than standing in the blazing sun of public eye," said Hossein Rassam, a former Iran adviser to Britain's Foreign Office.