Since a group of senior military officers, backed by thousands of armed soldiers, came close to toppling him on the night of July 15, Turkish President Recep Tayyip Erdoğan has sought comfort in the bosom of his angry, exhilarated people. The country has spent the past three weeks in a state of collective hyperventilation. The combination of nationalism and religiosity is like nothing I have seen in twenty years of following Turkish politics, and it is supposed to climax in a huge, government-sponsored “democracy vigil” in Istanbul on August 7.

The country’s public spaces have been the scene of countless such vigils, involving hundreds of thousands of Turks waving the star and crescent and vowing to prevent further treachery, while the Turkish media lionizes the heroes of the “resistance” of July 15. These include martyrs in Ankara and Istanbul who were crushed by tanks, farmers who set fire to their wheat fields upwind from an airbase taken over by coup leaders, and of course Erdoğan, who evaded death or capture by minutes but managed to get off an appeal via smart phone that brought millions into the streets. Even as he has reacted with sweeping purges of the military and civil service and the closure of dozens of Turkish media outlets, the president himself has become the personification of Turkish affront, his heroism uncontested, his snub, unsmiling features impressed on the national psyche as never before.

The epic qualities of July 15 and the evasion of a possible catastrophe were mostly lost on Western leaders, whose reactions to events were dictated by sympathy less for the besieged government than for the probable targets of its reprisals. John Kerry, for example, urged the Turks to “uphold the highest standard of respect… for the rule of law” when dealing with the coup’s perpetrators, while the EU’s foreign policy chief Federica Mogherini said, “We need to have Turkey respect democracy, human rights and fundamental freedoms.” In Ankara and Istanbul such comments were viewed by many Turks as deliberate slights to a nation that had shown heroism comparable to that of the Ottoman soldiers who repulsed a British invasion attempt on the Gallipoli beaches in 1915.

With considerable encouragement from the Turkish government itself, the feeling of national release has, for the time being, had a unifying effect. The infighting between Erdoğan’s ruling AK Party and the mainstream opposition parties, the center-left Republic Peoples Party and the right-wing Nationalist Action Party, is in abeyance, and the notoriously touchy Erdoğan has withdrawn thousands of suits filed in his name against people who allegedly defamed him on Twitter or in the press or verbally. The authorities have stopped charging for bus and metro services in Ankara and Istanbul (further incentive for people to attend the democracy vigils), and the names of public thoroughfares are being changed to commemorate the martyrs of July 15.

The strength of the Turkish reaction is only comprehensible if one appreciates the trauma of the coup itself. July 15 was a vicious attempt by a cabal of senior generals to place the country under a military dictatorship. It was carried out, as far as we know, in the name of a US-based Islamic preacher called Fethullah Gülen, who is the leader of a worldwide network of schools and whose movement has many followers in the Turkish bureaucracy. (He denies the accusation but Turkey is demanding his extradition.) Parliament, the presidential palace, and many other strategic buildings were attacked by aircraft and tanks, and military bases across Anatolia witnessed furious fire-fights between plotters and loyalists within the military and security appartus. In Ankara and Istanbul citizens and police confronted army units; from a stanchion of the Bosporus Bridge a marksman picked off civilians. Around 240 people—the great majority of them civilians—were killed by the putschists, and there were well over two thousand injuries.

Turkey has experienced three military takeovers since 1960, along with several foiled attempts. If these past interventions are anything to go by, the features of military rule this time around would have been executions, torture, and the suspension of free speech. With the army itself divided, civil war would have been a possibility. It is little wonder that in the febrile post-coup atmosphere foreign warnings over human rights have been regarded at best as uncharitable, and at worst sour grapes.

There is a widespread feeling among Turks that the West was behind the coup or had prior knowledge. Gülen has been in the United States for more than a decade and a half—he lives modestly in Pennsylvania—and the authorities presumably have a good idea of what he is up to and who is visiting him. According to James Clapper, the Director of National Intelligence, some of the Turkish generals who were arrested for their part in the coup were vital allies in the war against ISIS, and will be missed; “This is going to set back our cooperation with the Turks,“ he said. Among the detained officers was the Turkish commander of Incirlik, the airbase from which US aircraft conduct attacks and reconnaissance over Syria. Erdoğan has excoriated the Americans for “taking sides with the coup plotters.”

The president’s supporters have long believed that the US wants to damage Erdoğan because he is a strong leader who turned Turkey into a regional power. To hear ordinary people speak of the coup’s shady foreign “mastermind,” to read newspaper columns describing an outside plot to drag the country into civil war, you might never guess that the coup was in fact carried out by Turks, quashed by Turks, and that it was part of a wider power struggle between two Turkish organizations, the AKP and Gulen’s Hizmet (“service”) group.

The coup attempt has intensified the bond that Erdoğan enjoys with his supporters, illustrated on July 29, when he and they—including the families of the martyrs of July 15—paid each other homage in a cavernous auditorium attached to the sprawling presidential palace he recently built in Ankara. Into Erdoğan’s speech that evening went a toxic mix of Islamic chauvinism, pugnacity, and xenophobia. He announced a modern “independence movement,” took his usual pot shots at the West, and declared that he was the slave of God and ready for martyrdom. Was it possible, he asked, that the plotters were Muslims and Turks? “No!“ the audience shouted back. Erdoğan agreed: “They have nothing to do with this nation.“

All the while, the purges and security measures that the government began after the coup broaden and gather pace. Under the state of emergency that was declared on July 21, decrees have been issued to reorganize the armed forces and lengthen detention without charge from twenty-four hours to thirty days. In addition to some 10,000 Turkish military personnel who have been arrested for involvement in the coup, around 3,000 have been suspended or dishonourably discharged, including some 40 percent of the country’s admirals and generals.

To many Turks—again, their perspective differs starkly from that of the West—the purge is not too wide, but too late. Erdoğan has admitted that his earlier, “well-intentioned” alliance with the Gulenists against the country’s once-dominant secular establishment—a strategy that lasted until a falling out in 2012—was a mistake. That alliance saw secularists kicked out of public life; the Islamists are now eating each other.

In addition to hollowing out NATO’s second biggest army, the government is also purging professional associations and chambers of commerce; 8,000 private sector companies have reportedly been earmarked for investigation. Dozens of Gulen-affiliated schools and universities have been closed down. A bureaucrat friend told me that twenty-nine people had been suspended from his government department. As many as five hundred heads may roll in the foreign ministry.

This pattern will be replicated in every public institution across the country. If the purge hasn’t yet approached that of 1980, following the last (successful) coup, when 650,000 people were taken into custody and 1.6 million people ended up being barred from public sector employment, there is plenty of time. Some concerns are being aired among leftists and liberals that the government’s net will drag in innocents, but there is a general agreement that in exceptional circumstances the state must reassert its authority.

Human rights have been forgotten. It may not help that Turkey’s human-rights advocates are mostly Kurdish nationalists who recall the involvement of Gulenist officers and judges in some of the worst anti-Kurdish repression. In the words of one former army officer who was himself the victim of a Gulenist witch-hunt, “everyone hates the Gulenists.“

From Gulenists who were not involved in the coup to innocents denounced for personal reasons, not to mention the seventeen journalists who have been charged with membership of Gülen’s “terror group,“ it seems inevitable that there will be miscarriages of justice. Some of these may be irreversible if parliament, as Erdoğan has suggested it might, votes for the reintroduction of capital punishment.

On July 25, Jean-Claude Juncker, the president of the European Commission, commented that Turkey, “in its current state…is not in a position to become a member any time soon.“ But the feeling may be mutual. Only ten years ago there was overwhelming support among Turks for entry in the European Union. No longer. For most Turks, who have long given up all hope, or ambition, of joining a club that is itself in dire trouble, Europe’s verbal interventions in their national emergency are little more than an irritation. The failed coup of July 15 may indeed usher in a more vindictive and authoritarian Turkey, but for the moment people seem willing to accept the Erdoğan version of democracy if it preserves them from military rule under the Gulenists.

Research for this article was supported by the Pulitzer Center on Crisis Reporting.