The United States’s engagement in the Middle East since 2001 would be a comedy of errors but for the fact that it is not funny. It all began with the exploitation of a befuddled President George W. Bush by a group of neoconservative advisers who had long planned to invade Iraq and oust its President Saddam Hussein using phony arguments about Baghdad being a nest of terrorists and a repository of weapons of mass destruction. The bungled occupation was followed by a prolonged case of democracy building that essentially destroyed Iraq as a nation and eventually led to a sectarian government closely tied to neighboring Iran that had the temerity to ask U.S. forces to leave at the end of 2011.

Overall, George Bush’s adventure has rightly been described as the worst foreign policy disaster in the history of the United States, killing approximately 4,500 Americans and some hundreds of thousands of Iraqis while costing the U.S. taxpayer at least $5 trillion. And that judgment does not even consider how the U.S. intervention led to the entry of al-Qaeda into the country as a result of the power vacuum created. Al-Qaeda was followed by the birth of ISIS in neighboring Syria, a development that soon metastasized and expanded back into Iraq. Neither Iraq nor Syria harbored any terrorists before 2001, but they certainly have plenty of them right now, and quite a few of them are using American-made weapons captured without a fight from the U.S.-trained Iraqi Army.

The United States has also given open and covert support to rebel groups operating in Syria in the insane belief that overthrowing President Bashar al-Assad would lead to the creation of a new democracy. Just like in Libya, apparently. Even though almost everyone agrees that the “moderate rebel” is difficult to define in practice and has been sighted less frequently than the unicorn, Washington went ahead with a $500 million dollar program for the CIA and Pentagon to train a strike force of such creatures to turn loose in Syria. The hugely expensive effort trained a paltry 60 rebels, who returned home only to be quickly defeated by their more militant peers. Some were killed and others captured, so they were unceremoniously disbanded. Back to square one.

All of this seems to have benefited ISIS, which has an excellent grasp of social networking as well as a propaganda arm able to depict the group as the Islamic bulwark against the West and its values while also opposing the corrupt Muslim regimes that have betrayed both Allah and the faithful.

From the start, Turkey, which nominally opposes radical rebel groups like ISIS and Jabhat al-Nusra, has been curiously absent from the fray, instead arguing that the major effort should be focused on defeating al-Assad. Indeed, when I was in Istanbul last July bearded rebels were observed in the more fundamentalist neighborhoods collecting money for ISIS without any interference from the numerous and highly visible Turkish police and intelligence services. Turkey has also been surreptitiously buying as much as $3 million worth of smuggled oil from ISIS every day, virtually funding the group’s activities. Ankara has allowed ISIS militants to freely cross over the Syrian border into Turkey for what might be described as R&R (rest and recreation) as well as medical care and training. Weapons have been flowing in the opposite direction, cash and carry, some provided by the Turkish intelligence service MIT.

Given the plate of pottage that now exists in the Arab Middle East, Washington was understandably delighted when Turkey on July 23rd announced that bygones should be bygones and that henceforth it would play a more active role against ISIS. Or at least that’s what Ankara seemed to be saying. U.S. warplanes would be able to use the NATO air base at Inçirlik to bomb ISIS positions, a much shorter flight than from the facilities hitherto used in the Persian Gulf, though the move did not solve the real problem, which is that there are no forward observers on the ground to direct the bombs and missiles, which has meant that many planes return with their bomb loads intact.

But the euphoria in Washington must have been short lived as Turkey quickly demonstrated that its use of the United States as a partner in an offensive against terrorists could be considered window dressing or possibly even cover for quite different activity, as ISIS was not the enemy that Ankara had in mind.

Some understanding of what was going on in Turkish politics leading up to the shift to an ostensibly more aggressive role is essential. Turkey had held a parliamentary election on June 5th in which the ruling Justice and Development Party (AKP) failed to obtain a majority. Worse still, the Peoples’ Democratic Party (HDP), which is largely Kurdish, broke through the 10 percent barrier required to obtain parliamentary seats with more than 13 percent of the vote, much of it consisting of former AKP seats, making it a potential swing party in forming a new government.

President Recep Tayyip Erdogan, whose autocratic and increasingly Islamist style was the likely cause for the electoral shift, has been de facto running Turkey while Prime Minister Ahmet Davutoglu has been attempting unsuccessfully to find a coalition partner for a new government. Erdogan has been openly maneuvering for new elections by refusing to make any concessions to potential coalition partners and has attempted to create a political situation perceived to be favorable to the AKP, a tactic that has been described by an opposition leader as a “civilian coup.” November 1st has been proposed as a possible date, but it must be confirmed by the Elections Board. Erdogan had a personal stake in again going to the polls as he has been seeking to have his position as president upgraded with significant new powers, something that will require a substantial majority in parliament to amend the constitution.

The Turkish government of Erdogan has over the past several years been preoccupied with finding both internal and external enemies to justify its increasingly megalomaniacal heavy hand. This effort has largely been focused on the near-mythical foe Fethullah Gülen, who resides in Pennsylvania and who allegedly heads a somewhat cult-like organization called Hizmet (the Service). Gulen, who is a religious conservative, once was a political ally of Erdogan but the two eventually became bitter enemies. Erdogan while Prime Minister accused Gulen of setting up a secret government that was “terroristic” in nature and proceeded to initiate a number of purges of the military, police, judiciary, universities, and the media to destroy it. Nevertheless, the most recent election demonstrated that AKP for all its fear mongering was beginning to lose control and something had to be done to create a more compelling threat narrative. Enter the Kurds.

For three decades Turkey has been at war on-and-off with the Kurds, some of whom seek more autonomy within Turkey, while others favor the creation of an independent Kurdish state incorporating parts of Syria, Iraq, Iran and Turkey. By some estimates 18 percent of the population of Turkey is of Kurdish origin, concentrated in the rural southeast, making it the country’s largest minority. Kurdish identity has itself been suppressed through the Turkish assertion that Kurds are actually “mountain Turks.” Kurdish language and cultural manifestations have long been illegal in Turkey, though there has been some temporary loosening of those strictures in recent years under pressure from the European Union.

For many Turks Kurds are the existential enemy. A Kurdish state would lead to the dismemberment of the Turkish state and Syria has become the object of Turkish wrath in part due to concerns that al-Assad would unleash Kurdish terrorism along his 600 mile long and largely indefensible border with Turkey. Even though Turkey has had a mainly effective cease fire with the most powerful Kurdish armed dissident group the Kurdish Workers Party (PKK) since 2013, Erdogan evidently decided that it was good politics to break the agreement and declare war against the ancient enemy. And he chose to do it under the aegis of the U.S. led war on terror to increase its legitimacy in the media and in front of the international audience, hence the decision to support the Americans against ISIS.

The Turkish turnabout took place four days after a suicide bombing inside Turkey killed thirty-two civilians in Suruç in the Kurdish region. The bombing was attributed to ISIS not completely convincingly, but it nevertheless led to the round up and imprisonment of mostly Kurdish and leftist militants throughout Turkey plus a much smaller number of ISIS supporters. A major air assault on the PKK and other Kurdish targets in northern Syria followed with no warning to American and other allied soldiers and intelligence officers present in the area, a move that reportedly “outraged” U.S. military leaders. Ankara was clearly responding forcefully to fears of some kind of Kurdish state developing in northern Syria, a concern that had been growing after Kurdish militiamen liberated the border town of Tel Abyad from ISIS in June, provoking a pro-government newspaper to describe the Kurds as “more dangerous than ISIS.”

Since the wave of arrests and the initial air attacks, Kurdish reprisals against the Turks have killed more than 50 policemen and soldiers, while there are reports of an estimated 400 Kurdish militants dead at the hands of the Turks. It all guarantees that the tit-for-tat cycle of violence will continue.

As of last week, the Turkish Air Force had conducted more than 300 strikes against Kurdish targets versus only three against ISIS. Turkey’s war against ISIS was quickly and by design directed against the Kurds, including the Syrian Kurdish People’s Protection Units YPG militia which, together with the Iraqi Kurds, is supported by the United States and has been the most effective force in opposing ISIS. So Turkey, pretending to oppose ISIS, is actually attacking ISIS’s enemies and even placing in danger the American advisers known to be working with the Kurds.

All of which means that the United States is again looking on in astonishment over having been bamboozled, recalling Rudyard Kipling’s famous epitaph “A Fool lies here who tried to hustle the East.” One angry American general calls the development a “bait and switch,” while another commented that Erdogan “needed a hook” to go after the Kurds and lied to Washington to accomplish that. I might even suggest that the original suicide bombing that sparked the whole chain of events, which was carried out by a 20-year-old ethnic Kurd, might itself have been a false flag operation by MIT, designed to ease Turkish entry into a hot war ostensibly against ISIS but which would really be directed at the Kurds.

It remains to be seen if Erdogan will actually benefit electorally from the new war, as most Turks continue to be wary about military involvement in Syria and the instability has sent the Turkish lira plummeting on currency markets. He has already explicitly linked the opposition HDP to Kurdish terrorism in an attempt to discredit it and remove it from parliament, also calling for its 80 legislators to be stripped of their immunity so they can be prosecuted. And Erdogan certainly has plenty of precedents in mind when it comes to fabricating a powerful new external threat to revive one’s political fortunes.

Lost in the shuffle are Washington’s hapless diplomats and soldiers, trying to make sense of the long-abandoned U.S. interests, but that does not mean that Americans will be immune from blowback as the situation continues to deteriorate. The United States Consulate General in Istanbul, where I once-upon-a-time worked, came under gunfire two weeks ago, while Kurdish militants have already begun a new terror campaign directed against foreign tourist targets in Istanbul and along Turkey’s Aegean and south coast.

Philip Giraldi, a former CIA officer, is executive director of the Council for the National Interest.