The move comes after the deaths last week of Maj. Gen. Qassim Suleimani, an Iranian security and intelligence commander responsible for the deaths of hundreds of troops over the years, and Abu Mahdi al-Muhandis, a powerful Iraqi militia commander and government official, in an American drone strike outside the Baghdad airport. About 5,200 troops in Iraq and several hundred in Syria are now focused on fortifying their outposts instead of pursuing remnants of the Islamic State and training local forces.

What remains to be seen is what, exactly, Iran will do in retribution for the strike. In recent days, tens of thousands of pro-Iranian fighters took to the streets in Baghdad, chanting that “revenge is coming” to the United States.

In both Syria and Iraq, the United States has maintained an archipelago of outposts, bases and airfields, all connected by ground and air transport routes, where small contingents of American troops are either training local forces or working alongside them to carry out counterterrorism operations against the Islamic State.

The cessation of those missions, to instead focus on security, is likely to allow what remains of the terrorist group to reconstitute itself in the ungoverned spaces where it flourishes, much as it did when Turkey invaded northern Syria in October. Worsening the situation, Iran-backed militias that were also fighting the Islamic State have turned their attention toward the United States.

“The fight against ISIS has been significantly degraded by the tensions between the U.S. and Iran,” said Michael Knights, a senior fellow at the Washington Institute for Near East Policy. He cited the fact that American forces have recently been excluded from ground operations and have had airspace closed to them in the battle against the terrorist group, as a result of pressure on the Iraqi government from Iran-backed militias operating in the country.