BEIRUT — Iran's ballistic missile attack against bases hosting U.S. troops in Iraq was an unprecedented escalation, the first time Tehran has directly targeted U.S. military positions in the Middle East during four decades of confrontation between the two nations.

But the assault on the al-Asad air base in Iraq’s Anbar province and at a U.S. facility in Irbil didn’t cause any casualties, and the missiles didn’t hit areas where troops were located. The strikes seemed calibrated to avoid further escalation — while also being seen to exact revenge for the United States’ unprecedented killing of Iranian Maj. Gen. Qasem Soleimani.

After a few tense hours during which the Middle East seemed to move to the verge of a new war, it appeared Wednesday that a significant confrontation between the United States and Iran had been contained, at least for now.

President Trump said Americans should be “grateful and happy” that no U.S. personnel were harmed and refrained from making any further military threats. “Iran appears to be standing down, which is a good thing for all parties concerned and a very good thing for the world,” he said in a televised address.

In a tweet, Iranian Foreign Minister Mohammed Javad Zarif indicated that Iran does not intend any further attacks, saying that the military retaliation for Soleimani’s death had “concluded” and that Iran regards the bloodless strike as a “proportionate” response to his killing.

“Iran took & concluded proportionate measures in self-defense,” Zarif said. “We do not seek escalation or war, but will defend ourselves against any aggression.”

Iraqi Prime Minister Adel Abdul Mahdi said Iran gave Iraq prior warning that an attack was imminent, providing U.S. and Iraqi soldiers time to take cover. U.S. officials said they knew about the coming strike hours in advance.

U.S. military officials, who spoke on the condition of anonymity because they weren’t authorized to discuss the sensitive issue, said U.S. troops at al-Asad were sheltering in fortified bunkers by the time the first missiles struck, a little before 1:30 a.m. in Iraq. The missiles fired at Irbil missed the U.S. facility there entirely.

“At this point, the Iranians feel they have sent a message that they want to preserve their face in light of what’s happened, and they feel they have restored deterrence,” said Kamel Wazne, a political analyst in Beirut.

The defusing of immediate tensions did not herald an end to the broader crisis in U.S.-Iran relations, which was triggered two years ago by Trump’s withdrawal from the nuclear deal with Iran and imposition of new sanctions on that country. Trump said he was adding additional sanctions on Iran’s economy in response to the ballistic missile attack.

Iran, meanwhile, said it would continue to seek ways to avenge Soleimani’s death. Supreme Leader Ayatollah Ali Khamenei described the missile assault as a “slap in the face” and said Iran’s ultimate goal remains the expulsion of all U.S. troops from the Middle East.

A miscalculation could still trigger a new spiral of escalation, analysts said.

Iran’s use of short-range ballistic missiles against U.S. forces was significant and something of a gamble, said Afshon Ostovar, assistant professor of national security affairs at the Naval Postgraduate School and author of “Vanguard of the Imam: Religion, Politics, and Iran’s Revolutionary Guards.”

“Had they killed U.S. troops, we’d likely be headed to war,” he said. “But they telegraphed their move, giving us and the Iraqis ample time to move troops to cover. That suggests it was measured, intentionally limited and perhaps intentionally nonlethal.”

Iran used two missile variants capable of striking with pinpoint precision, experts said, suggesting Tehran may have aimed to avoid casualties while also showcasing its military strength. According to Iran’s Tasnim News Agency, the Revolutionary Guard’s air force division fired two types of missiles at the al-Asad base — the Fateh-313 and Qiam, both of which are short-range ballistic missiles.

Although the variants are considered highly accurate in their targeting capacity, “You can’t strike a populated military base with ballistic missiles designed to inflict massive destruction with 100 percent confidence that no one will be killed,” Ostovar said.

There is also a danger that Iran’s network of allied militias across the region would continue their attacks. Of specific concern is Iraq, where rocket attacks blamed by the U.S. military on the Iranian-backed Kataib Hezbollah militia killed a U.S. contractor in late December, sparking the cycle of violence that culminated in Soleimani’s killing last week.

Two rockets landed in the vicinity of Baghdad’s Green Zone, where the U.S. Embassy is located, on Wednesday night.

“This round is over, but tension remains high, and conflict could be ignited any moment by incidents that inflict U.S. casualties by Iranian proxies,” said Riad Kahwaji, who heads the Inegma defense consultancy based in Dubai.

Late Wednesday night, however, even Kataib Hezbollah suggested it was seeking to de-
escalate. “In these circumstances, passions must be avoided in order to achieve the most desired results, foremost of which is the expulsion of the American enemy,” the group said in a statement translated by the SITE monitoring agency.

Moqtada al-Sadr, who had ordered his dormant Mahdi Army to regroup for attacks to drive the United States out of Iraq, told his supporters to stand down and look to the Iraqi parliament to secure an American withdrawal. “The crisis has passed, especially after the statements from Trump and Iran,” he said in a statement.

Cunningham reported from Istanbul.