The fall of Ramadi, the capital of Iraq’s largest province, is a major defeat for the Iraqi security forces. It follows a period in which a number of strategic advances have been made by Iraqi forces elsewhere in the north and east of the war-torn country. Dreams of an offensive to defeat Islamic State in Mosul this year will now be crushed. Iraq will instead focus its resources and attention on liberating Ramadi, which lies just 60 miles to the west of Baghdad.

The complex realities on the ground will also lead to difficult choices being made on all sides of the conflict. Iraqi Prime Minister Haidar al-Abadi’s approval to send in the Shi’ite-dominated Hashid Shaabi paramilitary forces to the Sunni-dominated Anbar region will worry many, but it comes at the request of local Sunnis who are desperate to defend their areas against Islamic State. The Anbar governor, provincial council and local tribes have publically asked Baghdad to send in these paramilitary forces to support Iraq’s security forces and Sunni tribesmen.

Unlike in Tikrit, several Sunni tribes in Ramadi have already been resisting Islamic State for years now. As 3,000 Shi’ite fighters have deployed to the west of Ramadi following Abadi’s green light, 4,000 Sunni tribesmen have now been deployed in the west to prevent further Islamic State advances in Anbar. Sunni-Shi’ite military cooperation — aside from the official security forces that are themselves mixed — will be a crucial element in this campaign. Sunni tribal fighters are also officially part of the Hashid Shaabi in Anbar, so this paramilitary force is no longer exclusively Shi’ite.

U.S.-Iran relations in Iraq have also changed significantly over the years. The United States and Iran have gone from an era of undeclared but open warfare during the occupation to coordinated efforts to avoid collisions between air forces and even tacit military cooperation (with U.S. air strikes paving the way for Iranian-backed militia advances in the Salahuddin province) as Islamic State made advances across Iraq. The ongoing military campaign in Ramadi will further strengthen this trend: the U.S. ambassador today said the only condition the United States has for approving Hashid Shaabi deployment across Iraq is that they be under the command of the Iraqi security forces. In other words, the United States now accepts that they are an effective fighting force and needed on the ground, but the United States also wants to contain Iran’s growing influence.

Iraq is in a tough spot. Both the United States and Iran are strategic allies, and Baghdad needs both U.S. airpower and Iranian commanders on the ground to push back Islamic State. Getting them to publicly acknowledge each other will be impossible, but Baghdad will welcome this “condition” because it also wants to reassert its control and bring the Hashid Shaabi — which is now an official body under the office of the prime minister — under its own command.

Far from being a simple struggle for power between Sunnis and Shi’ites, both intra-Sunni and intra-Shi’ite dynamics are going to play a massive role in the failure or success of this military campaign, as well as the future of Iraq.

Sunni tribes — and even families — are bitterly split in Anbar, with kinsmen fighting with and against Islamic State. As the conflict in Ramadi develops, tribal revenge attacks will be bloody whichever way it ends.

Abadi also has hardline Shi’ites, especially elements still loyal to former Prime Minister Nouri al-Maliki, trying to undermine him at every turn. As he balances between the United States and Iran, he has to deal with powerful militia commanders who will resist attempts of the Iraqi state to take full control over their fighters even as they deploy alongside government troops.

CORRECTION: An earlier version of this article mistakenly said Ramadi is east of Baghdad. It is actually to the west.