Steven A. Cook is the Eni Enrico Mattei Fellow for Middle East and Africa Studies at the Council on Foreign Relations. His new book, “False Dawn: Protest, Democracy, and Violence in the New Middle East,” will be published in June.

Turkish President Recep Tayyip Erdogan, speaking on CNN Türk via a smartphone. (Burak Kara/Getty Images)

By the timetable of recent history, Friday’s attempted coup d’état in Turkey was roughly a decade behind schedule. For the better part of 40 years, beginning in 1960, the Turkish military overthrew governments it did not like around once a decade.

The almost-20-year interregnum between the last military intervention in 1997 and this weekend’s putsch created the impression among many in Turkey and the West that the coup era was over. During this period, the ruling Justice and Development Party, known as AKP, and its leader, President Recep Tayyip Erdogan, used both constitutional reforms and dubious criminal prosecutions of senior officers to bring the military under control.

This was why it was startling to so many, especially Turks, when tanks appeared on the streets of Istanbul and fighter jets streaked low across the sky. For a few hours, it seemed to those nostalgic for another era, when the military’s general staff portrayed itself as the bulwark against the excesses of Turkey’s civilian leaders, that the military had finally returned to its old form and was resetting Turkish politics.

But it was not to be. Although gunfire could still be heard Saturday morning, Erdogan, who looked shaken upon returning to Istanbul from his vacation, nevertheless reestablished control. Why? Beyond the obvious incompetence of the plotters, who failed to arrest the president and the prime minister (something that’s pretty much Coup 101) or establish control over the media — Erdogan was able to rally supporters into the streets via FaceTime, broadcast over CNN Türk — there are three related reasons why Erdogan and the AKP have prevailed.

First is that Turkey has changed since coups seemed a routine feature of the country’s politics. In previous eras, the military could easily intimidate opponents into upholding the secularizing and repressive principles of modern Turkey’s founder, Mustafa Kemal Ataturk. Yet as Turkey has become a more complex society and the AKP has sought to integrate the country globally, the conformity of Kemalism no longer works. In 1997, many Turks welcomed the military’s intervention to undermine Turkey’s first experiment with Islamist-led government. A decade later when the military sought to prevent one of the AKP’s founders, Abdullah Gul, from becoming president — opposing, among other things, the fact that Gul’s wife wore a headscarf — Turks protested, declaring that they neither wanted Islamic law nor military rule.

There had been moments before when Turks defied the military, but the 2007 protests that put the military on the defensive and helped pave the way for Gul’s presidency were a rather unambiguous indication that Turks would no longer submit to the military, no matter how often they were told it was in their interests.

Second, previous coups succeeded because they had significant civilian support. When the tanks rolled up to the Grand National Assembly and prime ministry on September 12, 1980, Turks breathed a sigh of relief because the military promised to bring an end to the violence between rightist and leftist forces that had taken thousands of lives in the previous four years.

The 1997 intervention, sometimes called the “blank” coup or “post-modern” coup because the military did not actually deploy, was the culmination of the military’s efforts to cooperate with women’s organizations, academics, cosmopolitan elites, the media and big business to destabilize and delegitimize a coalition government under the leadership of an Islamist party from which the AKP descends.

In contrast, on Friday night, the faction that sought to overturn the government had little popular support. When Prime Minister Binali Yildirim and then Erdogan himself called on Turks to defy what they called an “uprising,” and when both their supporters, and some detractors, responded, it was only a matter of time before the government regained the upper hand: Military intervention in politics has become an affront to whom Turks believe themselves to be.

Finally, the coup was bound to fail because of who Erdogan is, what he represents for his constituents, and what he has done since coming to power. The Turkish president is a politician of uncanny talents who has captured the imagination of roughly half the electorate that has voted for him in such large numbers since 2007.

Around the world, only former president Bill Clinton edges Erdogan in terms of political skill and charisma. To his devoted followers, Erdogan has corrected historic wrongs and injustices by overcoming an insular and undemocratic secular elite, given life to a new political and business class, and established Turkey as a regional, even global, power.

Yet it is not just how Turks respond to Erdogan on an emotional level that has made him the most important Turkish leader since Ataturk, but also the very fact that he has delivered. Since the AKP came to power, the Turkish public has enjoyed greater access to health care, better infrastructure, more transportation options, more money in their wallets and the opportunity to explore their Muslim identities in ways that were unacceptable in the past.

It is true that over the past several years, Turkey has ramped up repression of journalists, the AKP has sought to remake the judiciary, checks and balances on the executive’s power have been greatly weakened, and corrupt government ministers are beyond the reach of the law. Yet this authoritarian approach didn’t sway the president’s voters to back his overthrow. And the coup plotters wrongly calculated that their show of force would intimidate Erdogan’s supporters. Once Turks took to the streets, they swarmed tanks and detained soldiers until police could arrest them. Indeed, as Erdogan said Saturday, “There is no power higher than the power of the people.”

Erdogan has survived and has already portrayed the failed intervention as an assault on Turkish democracy. Yet he seems to have something other than democratic politics in mind. Arriving in Istanbul, he declared the coup “a gift from God … because this will help us claim our military from these members of this gang” — referring to followers of exiled cleric Fethullah Gulen, who was once a partner of the AKP, but has more recently become Erdogan’s enemy.

The implications are clear: AKP will now hunt down opponents — real or imagined — with impunity, consolidating Erdogan’s already formidable personal power and fueling his ambition to further transform Turkey. Rather than an opportunity for democracy, the failed coup will only consolidate Turkey’s elected autocracy.