For the militants of the Islamic State, the American drone strike that killed the Iranian commander Qassim Suleimani was a two-for-one victory.

First, the killing of General Suleimani removed the leader of one of the Islamic State’s most effective opponents, responsible for building up the alliance of Iran-backed militias that did much of the ground fighting to drive the militants out of their strongholds in Syria and Iraq.

The assassination has also redirected the wrath of those militias and their many political allies inside Iraq squarely against the American presence there, raising doubts about the continued viability of the American-led campaign to eradicate what is left of the Islamic State and to prevent its revival in both Iraq and neighboring Syria.

“This is precisely the sort of deus ex machina the organization needed, to give it room to operate and to allow it to break out of its current marginality,” said Sam Heller, an analyst at the International Crisis Group who studies the fight against the Islamic State, also known as ISIS.