Iranian President Hassan Rouhani speaks with reporters at the Saadabad Palace in Tehran on Feb. 11, 2017. Tensions between the United States and Iran have left the moderate leader particularly vulnerable head of a presidential election in May. (Ebrahim Noroozi/AP)

When the United States suddenly issued a ban on entry by nationals from Iran and six other countries, sending the world’s airports into chaos, Iranian President Hassan Rouhani gave a muted response.

“Let’s help neighboring cultures,
not build walls between nations,” the ­moderate leader posted on Twitter. “Let’s not forget what happened to the #BerlinWall.”

The comment, typical of Rouhani’s soft diplomacy, became fodder for critics ahead of his reelection bid this spring.

President Trump will not understand the references to walls, the conservative Ezzatollah Zarghami, a potential challenger to Rouhani, fired back. You should “speak to [Trump] the same way you speak to your critics,” Zarghami said.

A burgeoning crisis between Iran and the United States has threatened to undermine the pragmatic Rouhani, who was elected four years ago on promises to end the country’s isolation from the West. But now, amid new tensions with the Trump administration, Rouhani’s pro-dialogue approach is under attack. The shift — from detente with the Obama administration to open hostility with the White House under Trump — has left Rouhani particularly vulnerable as he gears up for a presidential vote in May.

In the few weeks since Trump took office, the two sides have sparred over Iran’s ballistic missile program, the ban on Iranian nationals entering the United States and new White House sanctions targeting Iran’s weapons systems. Trump’s then-national security adviser, Michael Flynn, announced that the United States was putting Iran “on ­notice” over its ballistic missile tests, which the White House said defied a U.N. Security Council resolution. Iran responded with more military exercises and a threat to “rain down” missiles on its enemies.

“The conventional wisdom is that if the U.S. really begins to crack down — to put Iran on the defense, keep it under threat, and take away some benefits — that it will work against Rouhani,” said Gary Sick, who was the principal White House aide on Iran during the 1979 revolution and subsequent holding of U.S. Embassy personnel as hostages.

Iran’s conservatives have yet to field a viable candidate to oppose Rouhani, said Sick, who is now a research scholar at Columbia University’s Middle East Institute. But in Iranian election campaigns, which normally last just a few weeks, “things happen very fast,” he said.

Rouhani, a cleric turned politician, has the political advantage of an incumbent. And, despite disagreements over policy and ideology, he appears to still have the support of Iran’s supreme leader, Ayatollah Ali Khamenei, whose broad power can make or break candidates. Khamenei recently nudged Rouhani’s chief rival — former president and right-wing firebrand Mahmoud Ahmadinejad — out of the race, after rumors swirled of a dramatic political comeback.

“It strikes me as unlikely that the regime will switch horses at this stage or that a rival can offer a compelling alternative to the electorate,” said Suzanne Maloney, senior fellow at the Brookings Center for Middle East Policy. But “making predictions on Iranian elections is a fool’s game.”

Given the uncertainty and the Trump administration’s more hawkish policies, Iran’s election, scheduled for May 19, “will not be an easy one for Rouhani,” said Abas Aslani, world news editor at Iran’s Tasnim News Agency. Iran’s Guardian Council, a clerical oversight body, will vet the contenders and announce the approved candidates in late April. Candidate registration has not yet opened, meaning there is still time for a conservative front-runner to emerge.

But if voters decide that Rouhani has failed on key promises, such as bringing economic growth through the careful diplomacy of the nuclear deal, “it will shake the president’s popularity” ahead of the election, Aslani said.

Indeed, the trouble for Rouhani started when Iranians, sick of a sluggish economy, grew sour on the 2015 nuclear deal he said would boost investment and ease poverty. That agreement — between Iran, the United States and five other nations — promised sanctions relief if Iran halted its nuclear enrichment program, and it was hailed as a diplomatic achievement.

Since then, some restrictions have been lifted. But others, such as those targeting Iran’s alleged financial support of terrorist groups, remain in place, sanctions experts say.

Foreign banks have also continued to avoid transactions with Iran, where corruption and money laundering are rife, said Richard Nephew, former principal deputy coordinator for sanctions policy at the State Department. Iran also resumed selling oil on the international market, but low prices stunted what many Iranians hoped would be a swift economic recovery.

“Residual sanctions, particularly those associated with Iran’s support for terrorism, continue to hamper [Iran’s] economic performance, but so, too, did Iran’s poor business climate and low oil prices,” said Nephew, who also served as Iran director on the National Security Council under President Barack Obama.

As a result, “the majority of people are not satisfied with the economy,” said Ali Omidi, professor of international relations at the University of Isfahan.

Unemployment reached 12.7 percent in the second quarter of 2016 — up from 10.9 percent the year before — according to the latest data available from Iran’s central bank, and oil and non-
oil-sector growth remained at 3 percent and 2.8 percent, respectively.

According to a poll published by the University of Maryland in January, a majority of Iranians now believe that Iran has “not received most of the promised benefits” of the nuclear deal. They also say that “there have been no improvements in people’s living conditions” as a result of the agreement.

“People are following the recent tensions [with the United States] with worry,” Omidi said.

Iranians “think Trump is an unusual person” who may deliberately “start a crisis,” he said.

On this point, Iranians might rally behind Rouhani. But it will depend on how aggressively the White House censures Iran, and on how Khamenei responds. The Trump administration has already floated a proposal to designate Iran’s Revolutionary Guard Corps, the country’s most powerful security institution, a terrorist organization. Such a move would have destabilizing effects around the region, where the Revolutionary Guard is active.

This administration “will likely really be ready to take risks to oppose Iran. It’s just a matter of how risky they are prepared to get,” Sick said.

It also depends “whether the supreme leader is going to walk away from Rouhani as the Americans get tougher,” he said. “He might decide to abandon his president or to stick with him. It’s difficult to predict.”