It wasn’t supposed to be like this. In October 2004, the European Commission offered Turkey a formal invitation to begin negotiations for membership in that exclusive club of democracies, the European Union. The Justice and Development Party (AKP), which had been in power for just two years at the time, hailed the commission’s offer as validation of its self-described Muslim Democrat worldview.

Yet only a few years after that triumphant moment, Recep Tayyip Erdogan—who was prime minister for 11 years before becoming president in 2014—began to veer away from the political reforms that were a condition of the EU’s offer, and away from the promise of a democratic transition in Turkey. The authoritarian approach to politics that Erdogan has pursued for the better part of the last decade seems destined to accelerate after last week’s failed coup d’état, as the president directs a widespread crackdown against his enemies, both real and perceived. Turkey today looks less like a liberal European democracy and more like the kind of one-man autocracy commonly found in the Middle East. How did this country, which so many journalists, government officials, and analysts had once believed to be a model for the Arab world, become a case study in “re-authoritarianization”?

The story begins 53 years ago, in 1963, when Turkey signed an association agreement with the European Economic Community in the hopes of becoming a member of Europe. For Turkey’s leaders at the time, the prospect of joining Europe represented the fulfillment of the secularizing and modernizing reforms of the country’s founder, Mustafa Kemal Ataturk. Turkey was then a country that featured some democratic practices, but only three years before had experienced the first of four coups d’état that the military would undertake in the ensuing 35 years.

Despite the association agreement, Turkey’s integration advanced at a glacial pace. There were spurts of progress that punctuated the ambivalence of European leaders leery of a country where the rule of law was weak and human rights were routinely violated—one, moreover, that lagged behind European levels of socio-economic development and that was overwhelmingly Muslim. The 1974 Turkish invasion and occupation of the northern part of Cyprus—now an EU member—that continues to this day did not help Turkey’s cause either. Turkey’s leaders for their part were frustrated with what they perceived to be European double standards when dealing with a Muslim society.

In 1996, there was a breakthrough when a Customs Union agreement provided an important link between Turkey’s economy and that of Europe; and, in 2001, the two sides agreed to the Accession Partnership for Turkey, which laid out a cooperative framework for Turkey’s eventual EU membership. The following year, the Turkish parliament passed three “harmonization” packages that made important changes to the penal code, the codes of criminal procedure, and the anti-terror law. The legislation also abolished the death penalty in peacetime—Erdogan’s supporters are now demanding its reinstatement—strengthened freedom of expression, and permitted broadcasts in Kurdish. (Kurds had previously been banned from speaking their own language because the Turkish state did not recognize them as an ethnic group. For years, Turkish officials referred to Kurds as “mountain Turks.”)

The liberalizing trend looked set to continue when Erdogan’s party first came to government in 2003. The AKP-dominated parliament passed an additional five reform packages—concerning, among other things, minority rights and the judiciaryin its first year and a half. This was a significant shift from past Islamist parties that regarded Turkish efforts to integrate with predominantly Christian Europe as a form of cultural abnegation. The reformists who founded the AKP, Erdogan among them, rejected this idea and, at the time of their election, claimed that membership in Europe was consistent with their own values. The practical effect of all these reform packages was substantial. The European Commission recommended that Ankara begin membership negotiations, though its endorsement was hedged. By Europe’s own metrics Turkey had taken important steps toward fulfilling the EU requirements for negotiations, but had not fulfilled them in their totality. Rather, the commission argued that the negotiation process itself would spur further reforms. Negotiations began in March 2005, but slowed down almost immediately as some European countries balked at the prospect that Turkey might actually become a member of the EU.

Ankara’s reforms began to slow down after that, but Turkey’s transition really began to go downhill in the spring of 2007 when the Turkish military’s General Staff made it clear, via a statement on its website, that the military did not want the AKP’s favored candidate for president, then-Foreign Minister Abdullah Gul, to assume the office because he was an Islamist. This was a critical moment in Turkish politics and one in which previous Turkish leaders would have folded almost immediately. Erdogan, sensing his party’s popularity and how much Turkish society had changed in the nearly five years since the AKP had come to power, refused to be intimidated. He called for new elections, which the party won with a broad coalition of pious and average Turks, Kurds, liberals, and big business that gave the AKP 47 percent of the vote. With his party’s renewed popular mandate, Erdogan nominated Gul to be Turkey’s 11th president.

In the midst of this showdown, the Istanbul police uncovered an alleged plot to overthrow the government. This was what came to be known as the Ergenekon case, which captivated Turkey from 2007 until verdicts were rendered in 2013. Initially, the investigation promised to root out Turkey’s “deep state”—an alleged network of military, intelligence, and civilian officials along with policemen, journalists, academics, business people, and mafia figures. Working in the shadows and beyond the law, the group’s goal was, Turks believed, to subvert the government and any centers of power that would challenge “the system” and this coalition’s interests in it. A few years after the Ergenekon case began, prosecutors pursued what was called the Sledgehammer investigation, which ensnared large numbers of senior military commanders in a suspected effort to bring down the government.

Given Turkey’s history of coups, the alleged schemes seemed entirely plausible. In time, however, it came to light that significant portions of the evidence in both Ergenekon and Sledgehammer were flimsy or fabricated, allegedly at the hands of prosecutors who were followers of the self-exiled cleric Fethullah Gulen. (Until 2013, the Gulenist movement—which Erdogan blames for last Friday’s attempted coup—and the AKP were partners.)

After that, Turkey’s democratic reversal expanded and accelerated. Erdogan was emboldened by the decapitation of the military and imprisonment of other opponents, at the same time that he was unrestrained by the now-dim prospect of EU membership. He moved to consolidate his personal power and in the process transform Turkish society. In addition to the trials, during which large numbers of officers were detained and civilian prosecutors armed with search warrants entered military bases searching for incriminating evidence, the government arrested journalists, often on specious charges of supporting terrorism; sued critics of Erdogan; imposed massive fines on businesses whose owners failed to support the AKP; and intimidated social-media companies like Twitter and Facebook to share data on their users. Through the pressure the AKP brought to bear on companies wanting to do business with the government, firms were encouraged to purchase media properties that could be counted on to faithfully report what the prime ministry wanted. The Turkish Radio and Television Corporation, Turkey’s national public broadcaster, and the Anadolu Agency, the state-run wire service, also became part of the AKP’s political operation. The result was a virtual ministry of information in the service of Erdogan and his party.

Then there were the courts. Less than a year after the military’s failed effort to prevent a Gul presidency, Turkey’s chief prosecutor brought a case to the country’s Constitutional Court in March 2008, alleging that the AKP had become a center of anti-secular activity and thus should be closed. When it rendered its verdict, the high court found evidence supporting the charge, but fell just one vote short of the seven (out of 11) needed to close the party. Instead, it was forced to pay a fine of $20 million. This was too close a call for Erdogan. The AKP’s genealogy included four parties that had been closed as a result of either a coup or a court order, and Erdogan was determined never to allow his party to meet the same fate.

The result was a constitutional amendment that Erdogan brought before the Turkish people in a September 2010 referendum that gave the AKP greater ability to pack the courts with sympathetic judges. The amendment, which was combined with other constitutional changes including protection of children’s rights, freedom of residence, and the right to appeal, passed by a wide margin. A little more than a month before last Friday’s failed coup d’état, Turkish Prime Minister Binali Yildirim sent legislation to the parliament that would give the government a freer hand in placing AKP supporters on the bench, further compromising the independence of the judiciary.

This authoritarian turn has made it relatively easy for critics to charge that the AKP was never and could never be a genuine force for democratic change. In hindsight, that is likely true. Erdogan is, after all, the man who declared when he was mayor of Istanbul in the 1990s that democracy was “a vehicle, not a goal,” implying that one could disembark whenever it suited one’s purposes. At the same time, it would be disingenuous to overlook the AKP’s first term from 2002 to 2007, when pragmatism and consensus marked Turkish politics. There were controversies, of course, but the five constitutional reform packages that Erdogan oversaw seemed to augur a more open, and even democratic, Turkey.

In time, however, confronted with challenges real and perceived from the military, the judiciary, and Gulenists, Erdogan and the AKP pursued a political strategy based on polarization. By the time the Gezi Park protests—which began as a demonstration to save green spaces, but became an outpouring of anger over police brutality, crony capitalism, and the arrogance of power—rocked the country in the summer of 2013, there seemed to be two Turkeys: supporters of Erdogan who revered the leader, and his opponents who were intimidated or repressed. There was very little middle ground. The situation deteriorated further when, in late 2013, Gulenists in the police and prosecutor’s office accused four government ministers, members of their families, and associates of Erdogan of mass corruption. The move transformed what had been a manageable political skirmish between Erdogan and Gulen into all-out warfare that is reaching is moment of truth this week.

The coup in Turkey, had it succeeded, would have toppled a government that was most recently elected with 49.5 percent of the vote in November 2015, and a president who garnered 51.7 percent support in August 2014. It would not have brought an end to Turkey’s democracy, as Turkish officials and some analysts have suggested, if only because Erdogan and his partners within the AKP had already undermined whatever progress the country made in the early 2000s. The current government itself is the product of an election that had to be rerun last November because Erdogan was not satisfied with the party’s results the previous June, when elections had taken away the AKP’s parliamentary majority. Erdogan’s widening purge and crackdown are just the logical conclusion of a story that has been unfolding for the better part of a decade. Turkey’s democracy has not been lost—there was no democracy for it to lose.