On May 30, Iraqi special forces stormed the southern edge of Fallujah under U.S. air cover, launching a new assault to recapture one of the last major Iraqi cities under the control of Islamic State militants. Iraq’s elite forces who are leading the fight have been trained by U.S. advisers, but many others on the battlefield were trained or supplied by Iran. It’s the latest example of how Washington has looked the other way as Iran deepened its military involvement in Iraq over the past two years.

In the lead-up to the assault, Gen. Qassem Soleimani, commander of the Quds Force, the special operations branch of Iran’s Revolutionary Guards, met with leaders of the Iraqi coalition of Shiite militias known as the Popular Mobilization Forces.

Sunni politicians in Iraq condemned the involvement of Soleimani and other Iranian advisers in the battlefield preparations, saying it could fuel sectarian tension and unleash a new round of Sunni-Shiite bloodletting. They also cast doubt on the Iraqi government’s assurances that the offensive is purely an Iraqi-led effort to defeat Islamic State. “Soleimani’s presence is cause for concern,” said an Iraqi member of parliament from Fallujah. “He is absolutely not welcome in the area.”

Leaders of the Shiite militias have pledged that they will not take part in the main offensive on the city, and will instead help secure nearby towns and lay siege to Islamic State fighters. But the battle over Fallujah highlights Iran’s growing military and political influence over Iraq, a country wracked by a complex civil war that leaves it open to outside manipulation.

If there is one regional player that gained the most from America’s gamble in Iraq, it is Iran. With its invasion in 2003, the United States ousted Tehran’s enemy, Saddam Hussein, from power. Then it helped install a Shiite government for the first time in Iraq’s modern history. As U.S. troops became mired in fighting an insurgency and containing a civil war, Iran extended its influence over Iraq’s major Shiite factions.

Today, the Iranian regime is comfortable taking a lead role in shaping the military operations of its Iraqi allies. There is no one to restrain Tehran, and the rise of Islamic State, which views Shiites as apostates, threatens the interests of Iran and all Iraqi Shiite factions.

The Iranian regime has several interests in its neighbor: Iraq provides strategic depth and a buffer against Saudi Arabia and other Sunni Arab states that are competing with Iran for dominance over the Persian Gulf. More broadly, Tehran wants to ensure that Iraq never again poses an existential threat to Iranian interests, as Hussein did when he invaded Iran in 1980, instigating a war that devastated both countries.

Hussein was supported by the Sunni Arab states and most Western powers. (The Shiites are the majority in Iraq, but since its independence from Britain in 1932, the country was ruled by the Sunni minority until the U.S. invasion in 2003.) Iran will do whatever is necessary to keep a friendly, Shiite-led government in power in Baghdad.

Iran has excelled at playing the long game, especially in Iraq. Tehran’s willingness to spread money to various proxies and factions gave it great agility in maneuvering through Iraqi politics. One cable sent by the U.S. ambassador to Iraq, Christopher Hill, to officials at the State Department in November 2009 estimated that Tehran’s financial assistance to its Iraqi surrogates ranged from $100 million to $200 million a year.

The Islamic Republic was also willing to invest across sectarian lines: Iran “recognizes that influence in Iraq requires operational (and at times ideological) flexibility,” Hill wrote in his cable. “As a result, it is not uncommon for the IRIG [Islamic Republic of Iran Government] to finance and support competing Shia [Shiite], Kurdish, and to some extent, Sunni entities, with the aim of developing the Iraqi body politic’s dependency on Tehran’s largesse.”

Like some of Iraq’s other neighbors, Iran used its largesse to fuel and prolong the Iraqi insurgency and civil war. The Iranian Revolutionary Guard Corps financed, armed and trained numerous Shiite militias that targeted U.S. troops and Iraq’s Sunni community. The Iranians provided explosives, machine guns, rocket-propelled grenades and other small arms. They also brought Iraqi militiamen to Iran to be trained in the use of explosives and as snipers.

After Islamic State militants swept through northern Iraq in June 2014, Tehran once again mobilized to protect the Shiite-led government from the Sunni militant threat. Soleimani traveled to Baghdad at the start of the crisis to coordinate the defense of the capital with Iraqi military officials. He also directed Iranian-trained Shiite militias — including the Badr Brigade and the League of the Righteous, two notorious militias responsible for widespread atrocities against Sunnis — in the fight against IS. With a weakened and corrupt Iraqi military, the militias proved crucial in stopping the jihadis’ advance.

Since mid-2014, Tehran has provided tons of military equipment to the Iraqi security forces and has been secretly directing surveillance drones from an air base in Baghdad. Iran has also sent hundreds of Quds Force fighters to train Iraqi forces and coordinate their actions.

And Iran has paid a price for its deepening military involvement. In December 2014, a Revolutionary Guards commander, Brig. Gen. Hamid Taqavi, was killed by a sniper in the Iraqi city of Samarra while he was training Iraqi troops and Shiite militia fighters. Taqavi was the highest-ranking Iranian official to be killed in Iraq since the Iran-Iraq war. Thousands of Revolutionary Guards gathered for his funeral in Tehran, where Ali Shamkhani, head of Iran’s Supreme National Security Council, told mourners: “If people like Taqavi do not shed their blood in Samarra, then we would shed our blood” within Iran.

For their part, Iraqi leaders argued that as long as the U.S. did not provide military assistance, they had no choice but to ask Iran for more help. “When Baghdad was threatened, the Iranians did not hesitate to help us,” Haider al-Abadi, the Iraqi prime minister, told a television interviewer in late 2014.

Although Abadi has signaled that he wants to be closer to the West, he needs the support of Iran and its Iraqi allies to keep his government in power. Without the Iranian-backed militias taking the lead in fighting over the past two years, the Iraqi government would not have recovered as much territory from the jihadists. Through a combination of funding, training for militias and political support, Iran will continue to extend its influence over the major Shiite groups in Iraq.

The U.S. and Iran now share common interests in defeating IS and maintaining a stable regime in Baghdad that can transcend sectarian conflicts. While the Obama administration and Tehran are not coordinating directly in Iraq, they essentially have an undeclared alliance.

Without committing far more U.S. troops and resources, there is little that Washington can do to counter Iranian power in Iraq. And Tehran will not hesitate to use its many levers of influence over Hussein’s former domain.

Mohamad Bazzi is a journalism professor at New York University.