As last weekend began, Turkey was plunged temporarily into violent chaos as troops attempted to overthrow the country’s government. The military’s move was loud and bloody, including bombs dropped on the parliament and presidential palace, but ultimately ineffective. Turkey’s elected government, led by President Recep Tayyip Erdoğan, reestablished its authority within hours.

As coups go, this was a total flop. The number of troops directly involved was quite small—enough to attempt the takeover of some critical government buildings and infrastructure—but far too few to seriously challenge the government. In the end, the effort reportedly cost the lives of 265 Turks, including 104 coup participants, as well as more than a hundred civilians caught in the crossfire. Most of the short-lived fighting between rebellious troops and police loyal to the government happened in Istanbul and Ankara, leaving the rest of the country largely untouched.

Turkey’s impressive military once knew how to manage a coup d’état. They pulled off full-fledged coups in 1960 and 1980, plus a “post-modern” one in 1997, forcing out a civilian government without actually rolling out the tanks. The military is the core institution of the Turkish Republic since its founding in 1923 out of the remnants of the Ottoman Empire. The creator of the army and the state, Mustafa Kemal, popularly known as Atatürk (Father of the Turks), wanted a powerful military to act as the guardian of the new republic’s cherished constitutional values—above all, secularism.

Thus, every so often, the Turkish military threw out a government it didn’t like, usually because it felt that the civilians were moving away from Kemalism. Since Turkey boasts the second-biggest army in NATO, the United States generally kept its protests to a minimum, not least because during the Cold War the Turkish military was a strategic necessity to keep the Soviets at bay. Neither did many in the West really mind that the Turkish military was keeping the country’s Islamic extremists at bay, too.

That legacy has been largely undone by President Erdoğan, who has ruled Turkey since 2004. His Justice and Development Party (AKP), while never directly challenging Kemalism—an unthinkable heresy—has gone to great lengths to undermine the military’s political power and moral authority, in order to dethrone secularism.

This is a necessity for the AKP, which is an Islamist party that seeks quasi-theocratic ends through quasi-democratic means. The military has always represented a stumbling-block to Erdoğan’s increasingly overt plans to re-Islamize Turkey. Although the country is 99 percent Muslim, the Kemalist legacy of official secularism meant that for decades Islam was kept out of politics in way that’s seldom encountered in the Muslim world. That the AKP has undone.

To achieve that, Erdoğan has ruled Turkey in a manner similar to how Vladimir Putin has run Russia. There are elections, sometimes of dubious validity. Increasing numbers of officials are appointed by the ruling party rather than elected. The state indirectly controls most of the media, with newspapers and websites the ruling party doesn’t like being shut down unceremoniously. Thuggish police do dirty work as needed. Arrest awaits more forthright regime opponents, real and imagined.

No Turkish institution has suffered more from the heavy hand of Erdoğan than the military. Its senior ranks have been purged several times in an effort to force out secularists in favor of officers of an Islamist bent. The biggest purge came with the so-called Ergenekon trials, which lasted from 2008 and 2013, and posited a vast military-led conspiracy against the government. Even in Turkey, which loves conspiracies in every form, this was far-fetched. Nevertheless, several top generals received extended prison terms for their alleged roles in the alleged conspiracy—which never seems to have existed outside the imagination of the AKP.

After that debacle, which destroyed the morale of secularist officers, many of whom left the service in fear and disgust, it’s difficult to see how the Turkish military could have managed to plan a serious coup against the ruling party. That’s where foreign-based plotters come in, according to the AKP and Erdoğan.

They have fingered an exiled Islamic leader in rural Pennsylvania, Fethullah Gülen, as the real motivator of last weekend’s coup. A 75-year old self-styled educational guru who lives on a compound in the Poconos (for an introduction to this truly bizarre story, read this), Gülen is unquestionably an opponent of the AKP, having been allied with it for years as it rose to power. However, he and President Erdoğan fell out in 2013 and the exiled imam has become Public Enemy Number One in Ankara, despite there being no real evidence that Gülen has anything to do with military coup planning.

Nevertheless, the abortive coup has given the AKP the green light to undertake a thoroughgoing purge of its enemies, real and imagined: secularists, terrorists, Gülenists, plus a wide array of political opponents. In the last couple days, Ankara has arrested more than 6,000 people, including most of the country’s military leadership. Judges are being fired by the thousands, as are civil servants deemed unfriendly to the AKP.

Vowing to “clean all state institutions of the virus,” President Erdoğan has threatened retribution as well as demanded the extradition of Gülen back home to face terrorism and treason charges. His equally vehement demands to restore the death penalty indicate where this may be headed, as has word of mass purges, in the many thousands, of the civil service.

In this, Erdoğan has demonstrated a discipline and planning that was altogether lacking on the part of the coup plotters. Given the speed and scope of this purge, the biggest in recent Turkish history, it’s clear that the AKP had lists of thousands of official enemies ready to go, once the right opportunity to clean house presented itself.

That the abortive coup did nicely. It’s remarkable that Turkey’s military—the second-biggest in NATO—with more than 500,000 troops on active duty, managed to stage a revolt against the government that amounted to not much more than a battalion.

Questions abound about what really happened on the night of July 15-16. Turks with experience of past military coups have noted how laughably small and inept this effort actually was. The plotters’ choice of targets was odd, to put it mildly. They took over very few installations, and weren’t very rapid in any event. They left the biggest media outlets untouched. The coup seemed to have little desire to connect to the public.

To top it off, the plotters made scant effort to seize or harm the president, whose whereabouts they knew. At the height of the short-lived coup, Erdoğan was flying on his private jet, returning to Istanbul from a holiday on the Aegean coast. Rebel F-16 fighters, fully armed for combat air patrol, intercepted the president’s plane, yet mysteriously they made no effort to shoot it down or even force it to land.

Since the first act of any coup d’état is neutralizing the regime’s leadership, that the plotters refrained from doing so, despite having easy opportunity, raises awkward questions about the entire affair.

The notion that the coup was a stage-managed drama—a pretext for the regime to purge its remaining enemies—may seem fanciful to Westerners, yet is entirely within the realm of possibility for Turks. This, after all, is the country that gave us the term “deep state” (derin devlet) to describe the secret forces that really control events. Turkish politics are filled with plots and coups, often of mysterious provenance, including shadowy terrorist groups that may—or may not—be controlled by the government, so it’s worthwhile asking what’s actually happening in Ankara.

This is especially important given Turkey’s outsized geopolitical role. It’s not only a key member of NATO that’s on the frontline of the struggle against the Islamic State, it’s the bridge between Europe and Asia. Serious instability in Turkey would threaten the entire region, from Southeastern Europe to the Black Sea over to the Persian Gulf.

It’s therefore not altogether comforting that President Erdoğan is a risk-taker who sometimes rolls the dice, as evidenced by his gamble last autumn with the Russians, causing an international crisis that easily could have led to all-out war between Ankara and Moscow. He survived that geopolitical game of chicken, though not without cost.

Did Erdoğan roll the dice again with a pseudo-coup to permit him a final settling of accounts with his domestic enemies? Little more than a year after taking power, Adolf Hitler “discovered” a coup plot among top-ranking Nazis, some of them his closest allies. The resulting “Night of the Long Knives” allowed the Nazis to purge the movement of powerful people they no longer needed, several dozen of whom were brutally murdered. This left Hitler as the unchallenged leader of the Nazi party, with fateful consequences.

Has something similar just happened in Turkey? The cultish Gülen movement enabled the rise of Erdoğan and his party to their current power position in Ankara, and it now represents a threat that the AKP wants to be rid of. Purging the military of any remaining secularists is always in Erdoğan’s interests. What’s happening in Turkey is something that NATO needs to ask directly—and quickly.

John Schindler is a security expert and former National Security Agency analyst and counterintelligence officer. A specialist in espionage and terrorism, he’s also been a Navy officer and a War College professor. He’s published four books and is on Twitter at @20committee.