Iran has its tentacles all over Iraq, and the United States has no one to blame but itself. It is a bipartisan failure dating back to the March 2003 invasion. Even after the Bush administration adjusted its course in Iraq, waging a large counterinsurgency campaign, the United States was so eager to wash its hands of a messy insurgency that it did little to roll back Iran’s gains. Nearly seven years after President Obama’s disastrous withdrawal from Iraq in December 2011, Iran and its Shia militias wield an enormous amount of power, and the militias’ political arms are set to play a major role in Iraq’s next government.

The seeds of this failure can be seen in the interrogation transcripts of Qais Khazali, the leader of an Iranian-backed militia, one of what the U.S. military used to call the “Special Groups.” Khazali’s interrogation logs were declassified by U.S. Central Command and released via the American Enterprise Institute on August 30. The hundreds of pages of files are part of the U.S. government’s push to designate Khazali, a militant with American blood on his hands, a terrorist. Khazali is now a politician, and his group, Asaib Ahl al-Haq, holds 15 seats in the Iraqi parliament. His rise was no accident. Khazali, who was in U.S. custody from 2007 to the end of 2009, told his interrogators then that Iran had long-term plans to infiltrate Iraqi society at all levels. And the Iranians have done just that.

The Special Groups were paramilitary units embedded in Muqtada al-Sadr’s Mahdi Army. Sadr has long been a Shia powerbroker in southern Iraq. The newly released files confirm that Khazali, who worked for Sadr, came to view his superior as a rival. They also confirm that Sadr’s Mahdi Army received funding, weapons, training, and advice from Iran and its chief proxy, Lebanon’s Hezbollah. The Shia militants primarily targeted coalition forces, killing hundreds of American soldiers. Khazali himself led such operations.

In March 2007, British commandos raided a compound in Basra, Iraq, and captured their targets: Qais, who led the Special Groups at the time, his brother Laith, and a Hezbollah military commander known as Musa Ali Daqduq. Qais was responsible for issuing the order to kidnap and kill five American soldiers in Karbala. Laith was Qais’s deputy, while Daqduq was responsible for organizing, training, and advising the Special Groups.

U.S. military interrogators interviewed Qais at least 70 times during his almost three years in detention. Qais often played coy, pretending not to know about key figures and groups in the Shia insurgency. Yet at other times he divulged important details about his leadership of the Mahdi Army Special Groups, as well as Iran’s role in fueling the fire in Iraq.

Qais was one of several figures with inside knowledge of Iran’s plans for Iraq. During one interrogation, he “let slip” that he had “direct contact with Iranian Islamic Revolutionary Guards Corps (IRGC) General [Qassem] Suleimani.” As commander of Quds Force, the infamous Suleimani is tasked with directing Iran’s expansion throughout the Middle East.

Iran wasn’t interested merely in giving the U.S. military a bloody nose in Iraq, although surely its leaders enjoyed watching American soldiers be killed and wounded by the militias they sponsored. “The ultimate goal of Iran is to destroy the Americans,” Qais said, according to one interrogation summary. In addition, Qais indicated, “Iran is using both the U.S. and the Iraqis to keep each other busy through fighting while Iran pursues their own agenda and most importantly, nuclear ambitions.

Qais provided copious information concerning Iran’s use of a vast network of Shia militias, many in competition with each other, to achieve its goals. Yet his interrogators seemed far less interested in the big picture of Iranian expansionism in Iraq than in extracting tactical information they could exploit, as well as how Qais might be used as part of an Iraqi reconciliation process.

The interrogations thus come across as shortsighted. Little effort was made to exploit Qais’s knowledge of the petty jealousies and rivalries within the Mahdi Army and among various Shia factions. And virtually nothing was done to target the network of training camps, weapon supply hubs, and other infrastructure inside Iran that supported the Shia militias. Iran never paid a price for its meddling in Iraqi affairs and its direct responsibility for the deaths of hundreds of American soldiers, even though Tehran’s culpability was obvious.

Many of the interrogations focus on Qais’s ideas for ending the Shia insurgency. He seems to have sensed his interrogators’ desire for reconciliation and positioned himself as the only man who could play a major role in dialing back the violence and ending Iranian involvement in Iraq. At times, his captors appear to have accepted Qais’s views uncritically. In June 2009, the U.S. military released his brother Laith and more than 100 Asaib Ahl al-Haq commanders and fighters. Qais was released six months later. The reason given: Qais and company were freed so they could take part in a reconciliation plan. The U.S. military believed that the Khazalis and their Iranian-backed terror group would lay down their arms and join the political process.

In exchange for Qais and his men, the U.S. government secured the release of a British hostage, Peter Moore, and the bodies of three of the four men who were kidnapped with him in the spring of 2007. Moore’s compatriots had been murdered by Khazali’s men; three of the bodies that were returned were riddled with bullet holes; the fourth was never recovered.

The U.S. military also handed over Daqduq, the Hezbollah special forces commander who had the ear of Hezbollah secretary general Hassan Nasrallah and Suleimani, to the Iraqi government in 2011 under the promise that he would remain in prison. Daqduq was freed within a year. Qais and Daqduq never paid for the kidnapping and murder of the five U.S. soldiers in Karbala or any of the other attacks they had orchestrated against U.S. forces.

Daqduq’s whereabouts are unknown, but he is thought to have returned to Hezbollah and resumed a senior leadership position with the group. The U.S. government promptly designated Daqduq a global terrorist after he was freed by the Iraqis.

Qais, his brother, and his militia never laid down their arms. He would later lead a portion of his militia into Syria to fight alongside Bashar al-Assad’s regime, at the behest of Suleimani. By 2014, the militia was battling the Islamic State, as well as terrorizing Iraqi minorities in areas it liberated from ISIS.

Qais Khazali is but one player to emerge from the Shia branch of the Iraqi insurgency as a major figure. Iranian-backed commanders Abu Mahdi al-Muhandis, Mustafa Abu Sheibani, Akram al-Kabi, Abu Duraa, and others lead their own militias and dominate what is known as the Popular Mobilization Forces, or PMF. Khazali mentioned these men and their connections to Iran numerous times during his interrogations.

Muhandis is the most notorious of them all. Khazali said that Muhandis’s “closest ties with Iran are with the IRGC” and that he resides in Tehran. The State Department listed Muhandis as a global terrorist, described him as “an advisor to Qassem Suleimani,” and detailed his extensive involvement with the Special Groups. Today, Muhandis leads the PMF, which is dominated by Iranian-backed militias who cut their teeth fighting U.S. forces in Iraq. These militias remain hostile to the United States to this day, even though America has backed the PMF in its fight against the Islamic State.

The PMF was formed in 2014 to battle Abu Bakr al-Baghdadi’s ISIS goons, but it has since become an official military institution answerable only to Iraq’s prime minister. In many ways it is analogous to Iran’s IRGC, which takes its orders from Iran’s supreme leader, Ayatollah Khamenei, outside the military chain of command.

As with Hezbollah, the Iranian-backed Iraqi militias are more than paramilitary formations. They are political actors and scored a major victory in Iraq’s parliamentary election in May. Running as the Fatah Alliance, they finished second behind Muqtada al-Sadr’s Saairun Coalition and will likely ally with Sadr’s party in parliament. While Sadr maintains a degree of autonomy, Qais noted repeatedly in his interrogations that Sadr and his men were supported in various ways by the Iranians. These two Iranian-backed movements will form the next Iraqi government and select the next prime minister, who will have exclusive control over the PMF.

Iran has played the long game in Iraq, but one whose outcome was by no means assured. The U.S. military heavily targeted Iranian-backed proxies between 2007 and 2009, forcing many of their leaders and fighters to flee to Iran. But President Obama was determined to fulfill his campaign promise to end all U.S. involvement in Iraq, whatever the cost. In 2012, he claimed that “we have responsibly ended the war in Iraq.”

However, the war in Iraq did not end just because Obama declared it was over. After he withdrew U.S. troops in December 2011, Al Qaeda in Iraq reorganized and took advantage of the growing insurgency in neighboring Syria. Khazali had warned his interrogators about the nefarious influence of the “salafis” and “wahhabis,” by which he meant groups like Al Qaeda in Iraq. But he also warned that Iran was ecumenical when it came to fighting Americans. “Detainee [Khazali] said that every group that is fighting in Iraq trained in Iran, including al Qaeda,” one log reads. The passages that followed are redacted, likely indicating that some in the U.S. government are still uncomfortable discussing this Shia-Sunni cooperation against their common foes. Other newly released interrogation files, which have also been redacted, allude to this anti-American arrangement as well.

By early 2014, Al Qaeda in Iraq controlled the Iraqi city of Fallujah and many towns in Anbar Province. By that summer, the terrorist group had seized nearly one-third of Iraq, including the city of Mosul. It renamed itself the Islamic State of Iraq and Syria. Thus the Islamic State was born. But the Sunni jihadists weren’t the only ones who capitalized on America’s retreat.

Buoyed by Obama’s precipitous withdrawal from Iraq, Iran expanded its influence there. Support for the Shia militias and their political parties continued unabated. Iran was able to enlist many of these militias, including Khazali’s Asaib Ahl al-Haq, to fight on the side of the Syrian regime against rebels and Sunni jihadist groups. This built their stature in Shia communities in Iraq, while raising fears among Iraq’s Sunnis that the militias were merely tools of the Iranian government.

When the Islamic State rampaged throughout central and northern Iraq, threatening Baghdad during the summer of 2014, Iraq’s military was on the brink of defeat. The Iranian-backed militias came to the rescue and spearheaded every major operation against the Islamic State. Iranian generals and IRGC officers embedded with the Shia militias to increase their effectiveness. Militia commanders were frequently photographed with Suleimani on Iraqi battlefields. Suleimani reportedly created battle plans and directed operations in some theaters.

The Shia militias, with Iran’s help, were instrumental in liberating Mosul, Ramadi, Fallujah, Tikrit, Baiji, and Sinjar. But the operations to liberate Iraqi cities from the Islamic State came at a high cost to Iraqi civilians.

Ironically, the U.S. military, which had been forced to reengage in Iraq by the rise of ISIS, abetted the militias by providing air support during their operations to clear the Islamic State from Iraq’s cities. U.S. airpower, in other words, supported the same Shia militias that had killed American soldiers and abused their own countrymen.

There is one aspect of Iran’s primacy in Iraq that has gone virtually unreported: its access to a vast recruiting base among Iraq’s Shia population. In Lebanon, Iran stood up Hezbollah, which has waged proxy war against Israel for over three decades and lived to tell about it. Today, Hezbollah is the most influential player in Lebanon, and its military eclipses the Lebanese Army. Iran was able to set up Hezbollah by recruiting from Lebanon’s 1.65 million Shia. Iran has more than 24 million Shia to recruit from in Iraq.

Iraq’s Shia militias have not been content with fighting the Islamic State inside of Iraq and Syria. As Jonathan Spyer noted in the last December, Qais Khazali visited the village of Kafr Kila on the Lebanese border with Israel, where he gave a speech highlighting his desire to take the fight beyond Iraq and Syria and provide direct support for Hezbollah.

“I’m at the Fatima Gate in Kafr Kila, at the border that divides south Lebanon from occupied Palestine. I’m here with my brothers from Hezbollah, the Islamic resistance. We announce our full readiness to stand as one with the Lebanese people, with the Palestinian cause, in the face of the unjust Israeli occupation,” Khazali declared.

Khazali’s threat is real. With Iran’s help, he branched out from a localized Shia insurgency in Iraq and expanded his operations into Syria. The rise of Khazali and other Iranian-backed Shia commanders was abetted by a feckless U.S. policy in Iraq. That war never really ended, and the United States and its allies will be paying the price for that failure for years to come.