(CNN) Two weeks ago, one of Iraq's top security officials asked a trusted Kurdish intermediary to deliver a message to Massoud Barzani, president of the Kurdistan Regional Government, the semiautonomous fief in northern Iraq which has been something of an American protectorate since 1991.

"Tell Massoud that war is coming if he doesn't back off," Hadi al-Ameri said, according to someone privy to the conversation. "Do not provoke us by counting on the Americans."

Ameri was referring to the oil-rich city of Kirkuk, which the Kurdistan Regional Government, or KRG, has controlled militarily for three years and politically for even longer. Iraqi forces had left the city in 2014 as their war with ISIS raged, but now that the terrorist group was on the run, Iraq had every intention of recapturing it.

On October 16 some 9,000 Iraqi government forces, including Shia militias under the command of Ameri, invaded and took Kirkuk in a matter of hours. With rare exception, Kurdish peshmerga, a professionalized guerrilla army, whose name translates as "those who face death," retreated northward in a snaking, convoy of Humvees, tanks and armored vehicles. Tens of thousands of Kurdish civilians also fled to Erbil, the capital of the KRG, where officials were plunged into a state of late-night chaos and confusion.

Long considered the Kurds' Jerusalem, Kirkuk had fallen without much of a fight. And what violence did occur was between two US allies, with American taxpayer-financed weaponry. American-made Abrams tanks operated by Iraqi forces fired on American-armed Kurdish peshmerga, who returned fire, destroying at least five American-made Humvees.

This is because in spite of its meek professions of neutrality, Washington did take a side in this conflict: that of Iraq's central government. But it did more than that by attempting to minimize the role its regional adversary, Iran, apparently played in the reconquest of Kirkuk. The commander of the Quds Force, the foreign expeditionary arm of Iran's Revolutionary Guards Corps, was reportedly instrumental in the Kirkuk operation.

Nothing better illustrates the incoherence of America's stance in the Middle East than the fact that it turned out to be on the same side as Major General Qasem Soleimani, who occupies a status within US intelligence circles somewhere between Professor Moriarty and Darth Vader. He and his proxies are believed by US officials to have caused hundreds of American fatalities and injuries on the battlefields of Iraq.

Yet it's hard to overstate what the Iranian operative has just pulled off. Not only did Soleimani out-marshal and humiliate Washington by brokering a cleverer and more cynical deal, which undercut its own vain attempts at conflict resolution, but he was then rewarded with US legitimization of his scheme. (Iran officially denied any involvement in the recapture of Kirkuk.)

All this occurred less than 72 hours after President Trump heralded a get-tough-on-Iran policy, which included the designation of Soleimani's parent body, the Revolutionary Guards Corps, as a terrorist organization. In his strategy statement, Trump said: "The Revolutionary Guard is the Iranian Supreme Leader's corrupt personal terror force and militia," and he promised, "We will work with our allies to counter the regime's destabilizing activity and support for terrorist proxies in the region."

Except the US just did the opposite in Kirkuk and alienated its longest and most stalwart counter-terrorism ally in Iraq, who, as the Kurds like to remind us, have never burned American flags much less attacked American soldiers.

JUST WATCHED Kirkuk on edge after Peshmerga pushed out Replay More Videos ... MUST WATCH Kirkuk on edge after Peshmerga pushed out 02:31

"We had so much trust in America," a top Kurdish officer told me last week. "We never thought America would accept Iranian proxies using American weapons against their allies." One of his colleagues put it even more plangently than that: "It might be better if we just join Iran's axis."

Such are the paradoxes and unintended consequences of how America wages its never-ending war on terror — by alienating its friends and empowering its enemies — in the name of national security.

America's singular focus on ISIS

In the three years since ISIS stormed the Iraqi city of Mosul in June 2014, the United States has had monomaniacal tactical focus on smashing Sunni extremist head-loppers at the expense of underwriting its long-term strategic interests.

In a rush to dismantle the so-called caliphate, Washington has assembled and empowered a host of sectarian actors with antagonistic agendas who have been forced into a tenuous polygamous marriage of convenience. But now that ISIS is on its back foot — it just lost its de facto capital of Raqqa in the same week as the Kirkuk drama, in large part because of the spadework of another Kurdish-led proxy army — that marriage is disintegrating.

"For America, it's all about counterterrorism and ISIS," said Emma Sky, the British former governorate coordinator of Kirkuk during the US-led occupation of Iraq. "Across the region, ISIS isn't people's number-one enemy. They're more at odds with each other. The US still doesn't understand this."

For the Kurds, the power struggles are as much internal as they are external. The Kirkuk crisis would almost certainly not have happened without two precipitating events which fell within quick succession of each other.

The first was a referendum for independence held on September 25. A symbolic, non-binding plebiscite, and the second since the US toppled Saddam in 2003, it nonetheless drew opposition from every regional and Western government (save Israel's ), which argued that the referendum violated the sovereignty and geographical integrity of Iraq -- concepts that hold mythical sway in foreign ministries more than they reflect brute reality in a deeply balkanized Iraq.

Conceived by Massoud Barzani and sold as a prelude to the world's largest stateless people, long reliant on the caprices and mercies of the great powers, attaining their century-long dream of establishing a homeland, the referendum was a domestic political victory in its breadth even if an international defeat. Ninety-three percent of Kurds voted in favor of independence, in defiance of just about everybody, not least of all Baghdad and Washington.

The second precipitating event was the death of Jalal Talabani, the first non-Arab president of Iraq and the eminence grise of the Patriotic Union of Kurdistan, or PUK, one of two shot-calling parties in Iraqi Kurdistan. Headquartered in the governorate of Sulaimaniya, the PUK had also commanded the peshmerga in Kirkuk and so the near-bloodless loss of the city on Monday can only have happened because of a prearranged agreement between that party and Baghdad.

Absent from the backroom dealmaking was the other, stronger shot-caller, the Kurdistan Democratic Party, or KDP, based in Erbil. This party is headed by Barzani and his family, who control the KRG's foreign policy and their own peshmerga paramilitary.

Kurds' 'Game of Thrones'

Iraq's President's Jalal Talabani attends the 11th Economic Cooperation Organization (ECO) Summit in Istanbul on December 23, 2010.

For decades, the PUK and KDP — which is to say the House of Talabani and the House of Barzani — have vied for dominance in northern Iraq, often aligning with their mortal enemy Saddam Hussein to get the better of the other in internecine disputes which have devolved into civil war. In recent years, the PUK has developed a close working relationship with Qasem Soleimani.

The plan was apparently set in motion around the time of Talabani's memorial ceremony in Baghdad on October 8. The dead leader's eldest son Bafel met with Iraq's Prime Minister Haider al-Abadi, according to a senior KDP official I spoke to, who speculated that Bafel "saw the obvious, an opening in the Kurdish political parties to exploit in his family's interests." Days later, Soleimani paid a call on Bafel to reaffirm Abadi's seriousness, according to Reuters, citing a PUK official.

Bafel was almost certainly acting under the instructions of Jalal's widow, Hero Talabani, who along with her sister Shahnaz, represent what remains of the Talabani brain trust.

"Jalal was the tactician, the strategist, everything," Nibras Kazimi, an Iraqi scholar and former advisor to the US Department of Defense, told me. "Hero and her sister were the enforcers. They handled money, they handled keeping people in line." But now their patriarch is dead, and their futures uncertain.

Challengers exist within the PUK to assume Jalal's throne, chief among them KRG's Vice President Kostrat Rasoul Ali and, the governor of Kirkuk, up until Monday, Najmaldin Karim, who are seen as Hero's top rivals within the party. Perhaps not coincidentally, both not only opposed Baghdad's reclamation of Kirkuk but were also driven from the city the instant it happened — in Ali's case, after peshmerga fighters loyal to him put up some resistance to Iraqi forces.

"If I go back, my life is in danger," Karim told Bloomberg . "Even the night when all this happened, I had to maneuver carefully to go to safety."

JUST WATCHED Iraq seizes disputed city from Kurdish control Replay More Videos ... MUST WATCH Iraq seizes disputed city from Kurdish control 01:45

In this telling, Hero has cast herself as a kind of Cersei Lannister of Kurdistan after her husband's demise, seeking to secure her political relevance and enormous fortune — the Talabanis are thought to be worth millions — by cutting a deal with Iran's master operative to undermine Barzani and scatter her enemies within the PUK. Not bad for someone unused to strategizing.

Bafel Talabani rejects the claim that the PUK and Iran orchestrated their own deal. "Unfortunately we reacted too slowly," he told Reuters. "And we find ourselves where we are today." (Attempts to reach Saddi Pira, the head of the PUK's foreign relations, for comment on this story were unsuccessful.)

One US national security official believes that machinations by Hero Talabani are the real story of the Kirkuk debacle. "Look at the crowd Barzani managed to draw in Sulaimaniya on the eve of the referendum," that official told me. "It was something like 25,000 people. Hero could never draw such numbers on her own. You think that didn't factor into calculations about what to do about Kirkuk?" Rather than submit to Barzani's dominance in the absence of her force-of-nature husband, she's underwritten her longevity by siding with Abadi and Soleimani.

Working in her favor is the fact that Iraq's prime minister is up for re-election in 2018. A Shia ally of Washington and Tehran, Abadi is looking to capitalize on his government's military victory against ISIS and brand himself the standard-bearer of Iraqi nationalism. The prime minister is facing fierce competition next year. Among his likely opponents are former prime minister Nuri al-Maliki , another Shia from Abadi's own political party, whose sectarian thuggishness against Sunni Iraqis helped invite ISIS back into the country; and Hadi al-Ameri, the Iraqi security chief who delivered the message to Barzani and is not just considered as close to Iran by US intelligence, but an active agent of Iran. (Ameri fought on Iran's side in the Iran-Iraq War under the aegis of the IRGC.)

To stand a chance at being given another term next year, Abadi had to regain Kirkuk — no premier can allow it to fall outside the hands of the central government. And he needed Tehran's help, from which he only stands to benefit in a forthcoming context with Iranian surrogate contenders for the leadership. "Iran wanted to expand its influence and remove the last obstacle to control all of Iraq," a KDP official told me. "The whole operation was planned and executed by Qassem Soleimani."

A busy Sunday

KDP officials blame the Talabanis for reneging on a late-hour agreement, brokered on the eve of the Kirkuk recapture, about how to proceed with negotiations over the fate of the city with Baghdad. At a meeting held in Dukan, Sulaimaniya, on October 15, Massoud Barzani, his son and intelligence chief Masrour, his nephew and KRG prime minister Nechirvan sat down with their PUK counterparts, including Hero and Bafel.

According to one of the attendees of the meeting, who spoke on the condition of anonymity, Bafel told the KDP that he had consulted Abadi as well as Americans and British diplomats about reintroducing Iraqi forces into Kirkuk. However, Bafel apparently denied reaching any formal agreement with Abadi; he was merely tabling a proposal for further dialogue with the central government and both powerhouse Kurdish parties.

Kirkuk fell within 24 hours.

JUST WATCHED Kirkuk governor: Time is right for Kurds' vote Replay More Videos ... MUST WATCH Kirkuk governor: Time is right for Kurds' vote 05:25

According to the The New Yorker , Soleimani met that same day with PUK officials in Sulaimaniya, not long after the bipartisan confab in Dukan had wrapped up. "It's not clear what was included in the deal," journalist Dexter Filkins wrote, "but the speculation is that [Soleimani] offered a mix of threats and inducements, including money and access to oil-smuggling routes."

Whether or not the US actively tried to forestall such side action is beside the point because the Kurds now view it as an accomplice to the seizure of its Jerusalem, a psychic scar already being likened to Saddam's " Arabization " policies of the mid-1970s when forced population transfers changed the demography of Kirkuk from a city with a Kurdish majority into one with a plurality of Kurds, Arabs and Turkmen.

America's misfire

Reproach is the soap of the soul in the Middle East, where American allies have a habit of speaking melodramatically when slighted or jilted, only to then return to the fold when they once again realize that aligning with even an unreliable superpower is better than not doing so. (The Kurds are first among equals in this regard.) But American credibility has taken a lashing in the last week. And even an overly emotional KDP can point, convincingly, to a trifecta of falsehoods coming from Washington.

First, the Pentagon denied any untoward military buildup south of Kirkuk by Iraqi government forces in preparation for the city's takeover. On October 12, Major General Robert White, the commanding general of US ground troops in Iraq, told reporters that Iraqi forces, including Shia militias, were in positions to the south of Kirkuk but only in order to protect the city of Hawija, which had just been freed of ISIS, from a jihadist resurgence. "And they haven't moved since they occupied," White said.

Nonsense, said a senior Kurdish intelligence officer. "We were feeding solid intelligence to coalition members, including the US, about Iraqi deployments. Detailed information on locations, numbers, groups and types of weapons in the field — including American weapons — days in advance of the operation."

I asked the US Army Public Affairs office if General White still stood by his assessment that Iraqi deployments were only in Hawija on an anti-ISIS mission. A spokesperson for the office didn't respond in time for publication.

I was shown an email sent by a Kurdish intelligence officer to various US lawmakers on October 12. "We are facing an unprecedented military threat by Iraq and its Shiite militias," the email read, "[a]nd possibly an imminent attack. "Thousands have been deployed near Kurdish front lines. These areas have zero ISIS presence. They are armed with heavy weapons, some American in fact, including tanks, armored vehicles, mortars and artillery."

The office of one US senator who received the email confirmed its authenticity but stressed that information delivered by foreign intelligence service takes time to vet and corroborate.

Next, Central Command called the exchange of artillery and gunfire between some PUK commanders who resisted orders to evacuate and Iraqi forces a "misunderstanding" and professed not to take a "side" between Baghdad and Erbil, a position President Trump, who once famously mistook the Quds Force as a Kurdish entity, reiterated on Tuesday on the White House lawn.

Finally, the Pentagon denied that any Shia militias were in Kirkuk. This, in spite of the demonstrable fact that Hadi al-Ameri and Abu Mahdi al-Muhandes, whom the US Treasury Department sanctioned in 2009 and described as an "advisor" to Soleimani, were present for the lowering of the Kurdistan flag at the city's provincial council building, and the raising of the Iraqi one. (Al-Muhandes was convicted in absentia in Kuwait and sentenced to death for planning lethal terrorist attacks against the US and French embassies there in 1983.)

The head of one notorious Shia militia , the League of the Righteous , which in 2007 killed five US servicemen in the Iraqi city of Karbala, even publicly thanked the PUK for its cooperation in the Kirkuk handover. "We salute and appreciate the courageous position of the peshmerga fighters who refused to fight their brothers in the Iraqi forces," he tweeted

The US has also, bizarrely, downplayed Soleimani's role in the Kirkuk affair. One State Department official told reporters last Thursday, "I'm not aware of any Iranian involvement in that, per se" — an assessment the Kurds find risible at best and iniquitous at worst.

The US dismissal of Iranian aggression against Iraqi Kurds also carries troubling implications in Syria.

A race-to-Berlin scenario is unfolding between US backed Kurdish-led paramilitaries and Bashar al-Assad's army in the campaign against ISIS in the eastern Syrian province of Deir Ezzor.

According to Lieutenant Colonel Rick Francona, the former military attache at the US embassy in Damascus and a CNN contributor, Washington's wishy-washiness on the Kirkuk question has sent a stark message to its other Kurdish allies in the Syrian Democratic Forces, as the US-backed forces are called: "We may not be there to protect you, either."

Follow CNN Opinion Join us on Twitter and Facebook

"Once ISIS has lost all or most of its territory in Syria as it has in Iraq, the Syrian regime will attempt to reassert its control over the areas now held by the SDF," Francona told me. "The Iraqis have set a precedent for that."

And if Assad and his Soleimani-built militias try to reclaim territory gained by the Syrian Kurds, will the U.S. defend or abandon its friends in that fight?

"There is no doubt that Barzani overreached with his ill-timed referendum and his belief in America's unqualified support for him," said Sir John Jenkins, the former British ambassador to Iraq. "But it should never have got to this point. It may not be about Iran for Abadi. But sure as hell it's about Iran for Iran. They must be loving it."