BAGHDAD — As Shiite militiamen began streaming toward Ramadi on Monday to try to reverse the loss of the city to the Islamic State, the defeat has given new momentum to Prime Minister Haider al-Abadi’s rivals within his own Shiite political bloc.

At the urging of American officials who sought to sideline the militias, Mr. Abadi had, in effect, gambled that the combination of United States airstrikes and local Sunni tribal fighters would be able to drive Islamic State fighters out of the city as fighting intensified in recent weeks. The hope was that a victory in Ramadi could also serve as a push for a broader offensive to retake the Sunni heartland of Anbar Province.

But as the setback brought the Shiite militias, and their Iranian backers, back into the picture in Anbar, intensified Shiite infighting appeared to leave the prime minister more vulnerable than ever. And it presented a new example of how developments on the Iraqi battlefield have sometimes instantly shifted political currents in the country.

“Abadi does not have a strong challenge from Iraq’s Sunnis or Iraqi Kurds,” said Ahmed Ali, an Iraqi analyst in Washington with the Education for Peace in Iraq Center. “It’s from the Shia side.”