As contentious as the 2015 Iran nuclear deal is in Washington, it has been even more divisive in Tehran.

Now, disappointment over the deal threatens to unseat a president. On Friday, Iranian voters will decide whether to give a second four-year term to incumbent Hassan Rouhani, whose signature achievement was supposed to put him on a glide path to reelection.

Instead, the nuclear agreement’s failure to lift the economy is at the heart of a surprisingly strong challenge from Ebrahim Raisi. He is a conservative cleric backed by the Revolutionary Guard Corps and the paramilitary Basij, security forces that wield a huge amount of political and economic clout. Subtle hints dropped by Iran’s supreme leader, Ayatollah Ali Khamenei, suggest that he, too, favors Raisi.

But Raisi, 56, considered a potential successor to Khamenei, has gained ground by accusing Rouhani of failing to capi­tal­ize on the agreement and, by extension, allowing poverty and unemployment to rise in a country that is awash in oil deals since nuclear-related sanctions were lifted. He has pledged to triple government subsidies, currently $12 a month for the poorest Iranians.

“Iranians are still hurting economically, especially from unemployment, and this has turned out to be a major weakness of Rouhani in this election,” said Farzan Sabet, a nuclear security fellow and Iran analyst at Stanford University. “Raisi has sought to exploit this weakness through a populist message.”

[Nuclear deal takes center stage as Iran’s election campaign gets underway]

All four remaining candidates in the race have said they would uphold the nuclear deal. Rouhani has gone further, vowing to seek the end of all remaining sanctions imposed for human rights abuses, ballistic missile tests and support for terrorism. His reelection would be welcomed by Europeans who desire more business dealings with Tehran and who would probably resist or ignore any U.S. efforts to slap nuclear sanctions back on Iran.

But if Raisi wins, both Iran and the United States would be led by presidents who consider the deal a bad one and are inclined to favor military strength over the soft power of diplomacy. In that case, the orphaned deal could have a short life span.

On Wednesday, the Trump administration imposed new sanctions on two Iranian defense officials and an Iranian company for supporting the country’s ballistic missile program. But the administration continued to waive broader sanctions on Iran that were eased as part of the nuclear deal, subject to periodic review. The timing, two days before the election, was coincidental, but it could remind Iranian voters of the chains on their economy.

“The deal won’t go anywhere next week,” said Suzanne Maloney, an Iran analyst at the Brookings Institution. “If it’s undercut by Iranian rejection of what the deal brought, it will be more difficult to anticipate it enduring more than months.”

The election will be held just before President Trump leaves on an eight-day trip to Europe and the Middle East, with his first stop in Saudi Arabia, a bitter regional rival of Iran. The juxtaposition is by chance, but it conveyed the sense that Washington and Tehran are on a collision course. A win by Raisi, who was involved in mass executions of political prisoners three decades ago, could provide the Trump administration with justification for a more confrontational approach toward the Islamic republic.

“If Rouhani wins, it won’t change their perceptions of Iran,” said Karim Sadjadpour, an Iran analyst at the Carnegie Endowment for International Peace. “If Raisi wins, it makes their case easier to portray Iran as the malign actor in the region.”

Rouhani has said the main choice is between continued diplomatic and economic engagement with the West and increased tension and isolation from the world.

Polls, suspect in Iran, offer little guidance.

An independent survey conducted by the Iranian firm Ayandeh last week showed Rouhani leading Raisi, 27 percent to 10 percent, but with 53 percent of voters undecided. A more recent poll, reported this week by the semi­official Fars News Agency, showed Raisi ahead of Rouhani, 48 percent to 45 percent. If no candidate surpasses 50 percent, a runoff will be held next week.

By any measure, though, the race has not been the cakewalk for Rouhani that was assumed, with nuclear-related sanctions gone and runaway inflation tamed. On paper, the economy is growing, with real gross domestic product up 6.6 percent in the past year. But much of the growth stems from Iran’s ability to sell its oil on international markets again. Few of the gains have trickled down to ordinary Iranians.

“The middle class and upper middle class in Tehran have ­money and want to be left alone to enjoy it,” said Djavad Salehi-

Isfahani, an Iranian economist who is a fellow at Harvard University. “Below the median income, the economy is the number one issue. Incomes have fallen except for Tehran, so people don’t feel better off and are susceptible to promises of cash.”

While Rouhani’s support is strongest in urban centers, Raisi has campaigned mostly in the more traditional rural areas. Iran has a long history of ballot box tampering. Suspicions of a rigged vote in 2009 led to street protests that were suppressed, often violently.

[Rouhani lashes out at rivals, criticizing security forces and clerics]

Rouhani seemed to have that tumultuous period in mind in February when he warned security forces that it was a sin to interfere in the election. State television has reportedly censored parts of a Rouhani documentary, and some journalists from reform-minded channels that support Rouhani have been arrested or summoned for questioning.

Rouhani, 68, has since showed himself to be an aggressive campaigner, pushing the boundaries on mentioning forbidden topics.

He berated the Revolutionary Guard for painting anti-Israel ­slogans on ballistic missiles before firing them, accusing the force of trying to sabotage the nuclear deal. He attacked Raisi for a record of “execution and imprisonment,” referring to Raisi’s role on a board that sentenced thousands of political prisoners to death. He said his campaign sends a message to “the extremists and those who use violence that your era is over.”

“To a certain extent, Rouhani’s attacks appear to be even harsher” than during the 2013 campaign, said Reza Akbari, a researcher of Iranian politics at the Institute for War and Peace Reporting.

Rouhani seems to be positioning himself as the anti-establishment candidate who dared to negotiate with the enemy, the United States, to secure the nuclear deal, known officially as the Joint Comprehensive Plan of Action (JCPOA). If his strategy does not work, he would become the first president in Iranian history to lose a reelection bid.

“Maybe what this is all about is not a challenge to the JCPOA as much as a challenge to who will benefit from the JCPOA,” said Hadi Ghaemi, director of the New York-based Center for Human Rights in Iran. “We haven’t had much benefit of sanctions being lifted so far. But that is not a permanent state of affairs. Whoever can make the economic opening happen will reap the ­benefits.”