“When the fighting breaks out between Arabs and Kurds, whose side will the Americans be on?” This was the message that Masoud Barzani, the president of the Kurdistan Regional Government and leader of the Kurdistan Democratic party (KDP), instructed his chief of staff to have me convey to senior U.S. officials in Baghdad in 2010. I was serving as the political adviser to General Raymond T. Odierno, the commander of U.S. forces in Iraq. Nuri al-Maliki, then the prime minister of Iraq, and Barzani, concerned by rising tensions between Arabs and Kurds ahead of the 2010 national elections in Nineveh province, had asked General Odierno for help in preventing conflict. We had devised a system of joint check points to facilitate cooperation between the Iraqi Security Forces, the Kurdish Peshmerga, and the U.S. forces, and to ensure all forces remained focused on defeating al-Qaeda in Iraq.

A key part of the plan was to ensure freedom of movement for Atheel Nujaifi, Nineveh’s Sunni Arab governor, who had been elected the previous year on an agenda to roll back the gains the Kurds had made in the province since 2005. Determined to test the new security arrangements at the earliest, Governor Nujaifi decided in early February 2010 to make a trip to the town of Tel Kaif, in a part of the province which the Kurds lay claim to. Over Kurdish objections, the U.S. forces decided that the visit should go ahead. In response, the Kurds brought down reinforcements and tried to prevent the trip from taking place. Crowds of Kurds gathered to block the governor’s convoy; in the resulting melee, shots were fired. The Iraqi police detained 11 Kurds for incitement, and on suspicion of attempting to assassinate Governor Nujaifi.

I was awakened at 2 a.m. by a phone call from Murat Ozcelik, the influential Turkish ambassador to Iraq. He had received a report from Ankara that the Kurds had invaded Mosul, the largest city in Nineveh province. I investigated and soon discovered that there had been no invasion; instead, Kurdish forces had kidnapped a number of Arabs in Nineveh in retaliation for the arrest of the Kurds. President Barzani was furious. Every time he turned on his television, he saw footage of American tanks in a Kurdish village, and F-16s flying overhead. The Kurds had been highly supportive of the United States—not a single U.S. soldier had been killed by a Kurd. So why, he asked, had the Americans behaved this way towards Kurds?

Back in 2010, we did not need to answer Barzani’s question. We could mediate a deal whereby the kidnapped Arabs were swapped for the Kurds accused of attempting to assassinate the Governor of Nineveh. We had close relations with the Turks, and convinced them to back off. For once, everyone seemed happy with this solution, and things calmed down. We were the indispensable ally.

And then we weren’t. And Iran was.

Iran increased its influence during the negotiations to form a government in Iraq after the tightly contested  2010 elections. Iraqiyya, led by Ayad Allawi, won 91 seats; Maliki’s bloc, the State of Law, came in second with 89 seats. After much heated internal debate, Vice President Joe Biden determined that Washington would support the incumbent, insisting that Maliki was “our man,” an Iraqi nationalist, and would permit a contingent of U.S. forces to remain in Iraq post-2011 when the security agreement expired. But despite considerable arm-twisting, the United States could not convince its allies to support a second term for Maliki. Sensing an opportunity, Qassim Suleimani, the head of the Iranian Revolutionary Guard Council, pressured Muqtada al-Sadr, an influential and anti-American Shia cleric, to support Maliki on the condition that all U.S. troops would pull out of Iraq and that Sadrists would be given government positions.

Thus it was that Iran ensured Maliki remained as Prime Minister. The Obama administration, in its rush for an exit from Iraq, gave up the American role of “balancer,” of moderator, of protector of the political process, withdrawing its soft power along with its hard.

Secure in his seat for a second term, Maliki pursued a series of sectarian policies. He accused Sunni politicians of being terrorists, forcing them to flee the country; he reneged on his promises to the Sunni Awakening leaders who had fought against al-Qaeda in Iraq; and he arrested Sunni protestors en masse. This created the conditions that enabled ISIS to rise from the ashes of al-Qaeda in Iraq and proclaim itself the defender of Sunnis against the Iranian-backed sectarian regime of Maliki.

In 2014, ISIS took over Mosul, and all the U.S.-supplied vehicles and equipment that the Iraqi Security Forces left behind as they fled. It was only then that Washington re-engaged. But it was narrowly focused on leading a coalition in the tactical fight against ISIS. It did not address the strategic issues of the political dysfunction and contested governance of which ISIS is the symptom.

Now, with the threat of ISIS now greatly reduced and with the 2018 elections on the horizon, Iraqi and Kurdish politicians are already positioning for the day after.

Barzani calculated that the position of the Kurds was strengthened, as during the fight against ISIS they had received weapons directly from the international community and had extended the territory under their control to include Kirkuk. He believed that now was the best time to negotiate separation from Iraq, so he pushed ahead with the referendum on September 25, 2017—including in the disputed territories—over the protests of the Iraqi government, Turkey, Iran, the United States, the UN, and European countries.

Barzani viewed Kirkuk’s annexation as essential for Kurdistan to achieve independence. But no Iraqi prime minister can afford to lose Kirkuk—particularly one seeking re-election next year. Kirkuk has vast stores of oil. While Kurds constitute its majority, the city has significant communities of Arabs and Turkmen, who are both Sunni and Shia. And many of them have made known they do not want to be part of an independent Kurdistan.

Barzani’s gamble has not paid off. He believed that the referendum would serve as a rallying call for all Kurds and deflect attention away from his remaining in power beyond his legal term as president, and shield him from complaints about KRG corruption and mismanagement. What he failed to foresee was that his main rival the Patriotic Union of Kurdistan (PUK), whose leader Jalal Talabani died recently, would purposefully set out to weaken him by doing a deal with the Iraqi government to allow Iraqi security forces to enter the city without opposition. And behind the deal was the hand of Qassim Suleimani. Not since 1996 has there been such betrayal by one Kurdish political party of another.

Barzani was no doubt asking once again whose side the United States was on when the Iraqi army and Shia militias drove into Kirkuk province with M1 Abrams and Humvees, taking control of the airfield, oil fields, and the government building and pulling down the flag of Kurdistan.

The United States stated that it would not take sides in what it viewed as a dispute between the Iraqi government and the KDP, instigated by Barzani. Washington is angry that despite its warnings, Barzani went ahead and carried out the referendum. And it insists that it continue to support a one-Iraq policy, and that the focus of all groups should remain on fighting ISIS.

Barzani feels betrayed by America yet again. He has never forgotten how it let down his father in his moment of need in 1975, after the Shah of Iran suddenly cut support to the Kurds in return for Saddam Hussein’s recognition of Iran’s territorial demands. Mullah Mustafa Barzani had turned to America for aid, but Henry Kissinger refused and Kurdish resistance collapsed. Now when Barzani looked to the United States for support, he was told the current crisis was of his own making.

Close up, this looks like a success for Haider al Abadi, the man America wants to win the 2018 elections because it believes he is “our man,” an Iraqi nationalist, and will permit a contingent of U.S. forces to remain in Iraq.

But zoomed out, this appears to be yet another Iranian success. Iran is showing everyone in the region that it is the indispensable ally—not the United States. It is securing its corridors across Iraq and Syria, mediating between the different groups on the ground, while the United States occupies a shrinking space. Once more, Iran is playing the key role, helping to broker a deal between the PUK and the Iraqi government and guiding the Shia militias supporting the Iraqis. Iran has every interest in maintaining these militias—making it increasingly difficult for any Iraqi prime minister to demobilize them. And Turkey, which used to be a U.S. ally, is moving closer to Iran and Russia.

A compromise of some sort could be reached on confederation for Kurdistan and a special status for Kirkuk. But that would require mediation. And it is unlikely to be from Americans.

Why should this matter? Because the Iranian settlement will not bring stability to the region. It will endure long enough to defeat U.S. interests and allies. But left unchecked, Iran and its allies will sooner or later come into collision with Israel. And then the U.S. will be forced to take action.