On the evening of 15 July, Halil Saltik was sitting in his first-floor barbershop drinking black tea, a cigarette wedged between his fingers, when he noticed that traffic was blocked at the junction a few hundred metres away. Istanbul's Cengelkoy neighbourhood is usually busy, but something felt wrong. Then he heard the pop of gunshots.

Saltik stormed downstairs. At the end of the street, he saw gun-wielding soldiers straddling military trucks. Istanbul was still reeling from an Isis attack on the airport two weeks earlier, in which 48 people were killed. He wondered if there had been another bombing.

But this time, the soldiers were not here to protect. They were the attackers, and they had opened fire on residents who poured into the street to block them. At least one civilian had been killed. There were now rumours that tanks had blocked the Bosphorus Bridge, severing Istanbul's Asian and European sides.

Saltik ran up a nearby hill overlooking the bridge with its blue-lit pillars. Usually, it would be swarming with cars. Now, there was no movement. Hurrying home, he heard the prime minister on TV uttering the words Turks assumed were a thing of the past: military coup. There was still no sign of the president, Recep Tayyip Erdogan.

Saltik, who is 38, has shoulder-long jet-black hair and a beard. He wears a leather wristband several inches wide, a big silver ring with the star and crescent from the Turkish flag and a red felt fez. That's right, a fez. He is a man beset by blazing, patriotic feelings, and he wants you to know it.

"This can't be happening! Come outside," he yelled to his neighbours. He said a quick prayer. By the time he got to the bridge, the group he was marching with had grown to 300 people.

Across Istanbul, civilians were trying to stop the coup. In Taksim, the central square, men threw themselves at tanks. On the streets, drivers tried to cut off the tanks, only to see their cars crunched like ping-pong balls. In the capital, Ankara, jets fired at the parliament. For two hours, there was no word from President Erdogan, who was vacationing in the resort town of Marmaris.

But Erdogan has spent over a decade building a dedicated personal following, and his cohort didn't need a cue. Around Saltik, people shouted, "We are ready to die for the nation." For a while, though, he didn't fully comprehend the severity of the situation.

"We didn't believe the soldiers would shoot at us. In Turkey, every man is born a soldier," Saltik recalls a week later. I arrived in Istanbul two days after the coup attempt and am here to find out more about the people who rallied around the president. "But when we saw those men crouch and take aim at us, I thought, 'They are not our soldiers.'"

Soon, bullets were flying. One of them hit a man in front of Saltik in the head and he went down. Tanks began firing shells but the crowd didn't yield. When Erdogan appeared on national TV two hours after the coup started and urged more people to flood the streets, they did. Eventually, the plotters backed down. Then came the revenge.

As dawn broke, mobs descended on soldiers, even after they had surrendered. There were scenes of civilians, Turkish flags hanging from their necks like giant aprons, whipping soldiers with belts. A burly, bearded man kicked troops who were huddling and crying in a pile of bodies. One soldier cowered in a foetal position as a crowd stomped on his bloodied face.

The way the coup was thwarted illustrates how Erdogan has transformed Turkish politics. He has chipped away at the Turkish state's century-old secularist roots and instead nurtured a potent mix of political Islam and militarism. On top of this he has built a strong cult of personality that, on the night of the coup, allowed him to assume the role of a conductor, leading the defence of the republic as if he were guiding an orchestra.

Erdogan set the tone when he beamed up on CNN Turk, via FaceTime, appearing like some doyen of the digital era, as opposed to the ageing generals who were trying to unseat him (ironically, lest we forget, Erdogan is himself a frequent censor of social media). Then, to cinematic effect, he ordered all mosques across the country to call for prayer, rendering any pretext of a division between state and religion completely hypothetical.

"My hair stood up," says Abdullah Aksoy, an Erdogan loyalist. As majestic prayer calls wafted over Istanbul, Erdogan's private plane sliced through the night sky, dodging rebel jets, to bring him back to Istanbul. On the ground, his followers hurled themselves at tanks and pounded their boots in the bloody faces of enemies of the state. Had Erdogan been asked to direct a film about foiling a coup, this is what it would have looked like.

At least 265 people were killed in the attempted putsch. After the violence, Erdogan embarked on a purge of people deemed linked to Fethullah Gulen, a septuagenarian exiled cleric whom Erdogan immediately accused of being the mastermind.

Since then, at least 23,000 have been arrested and 80,000 fired or suspended. Warrants went out for high-profile human rights activists, academics and, peculiarly, former football star Hakan Sukur. Some of the arrested were tortured, beaten and raped, according to Amnesty International. More than 1,000 schools, dormitories and universities were shut, as were over 130 media outlets. The army was cleansed of thousands of members.

People shouted: 'We are ready to fight for the nation. In Turkey every man is a solider'

While Turkish and foreign critics worry that Erdogan is turning Turkey, once a democratic vanguard in the Muslim world, into an Islamic autocracy, his supporters have called for the death penalty to be reinstated. And they are tired of European arrogance.

Read more: All the awful things that will happen in 2017

"If we had been France, Europe would have called this the Second Revolution," says Huseyin Gamsiz, a pro-Erdogan protester I meet in Taksim Square. "We have acted very Western. We have shown that we value democracy. We laid down in front of tanks," he says. "The EU thinks they have us on a leash like a dog."

All this made me wonder about these stalwarts of Erdogan, who entrust the welfare of their nation to one man and who during anti-coup protests hung huge banners from buildings addressing Gulen: "We'll hang you and your dogs with your own leashes." Who are these people?

Recep Tayyip Erdogan was himself a victim of state repression. In 1997, when he was mayor of Istanbul, Erdogan publicly recited a poem from the early 20th-century nationalist writer Ziya Gokalp: "The mosques are our barracks / The domes our helmets / The minarets our bayonets / And the faithful our soldiers."

In proudly secularist Turkey, such a blend of militarism and religion was dangerously unorthodox. The state convicted Erdogan for inciting religious hatred, sentencing him to ten months in prison - of which he served four - and banned him from political office. This was a seminal experience for Erdogan. As late as 2011 he proclaimed, "We are the voice of the voiceless!" to a crowd of supporters in Istanbul. "They sent me to prison in this city."

Erdogan might know how to fire up a crowd, but irony seems lost on him. Earlier this year a German satirist called Jan Böhmermann used a poem to insult not only the president's intellect and his alleged sexual preferences (ranging from animals to children) but also the size and smell of his, well, durum (a Turkish wrap). Böhmermann wanted to expose how German profanity laws limit freedom of expression and Erdogan, never one to let a personal insult slide, took the bait. He demanded that Germany prosecute the comedian, which the law allows for. Chancellor Angela Merkel acquiesced.

England, meanwhile, does not have German laws, and Erdogan could not stop the Spectator from announcing its own President Erdogan Offensive Poetry Competition in the weeks before the EU referendum. The winner? The new foreign secretary Boris Johnson: "There was a young fellow from Ankara / Who was a terrific wankerer / Till he sowed his wild oats / With the help of a goat / But he didn't even stop to thankera."

From Western media, you might get the sense that the current struggle for Turkey is between Islamism and secularism, between democracy and tyranny. That is part of the battlefield, but not all of it. Erdogan has sought to empower a long-oppressed Islamic underclass, but he has also lifted millions of Turks out of poverty. His supporters see him as a man of the people, who rose from modest means to the country's highest office, where he has given opportunities to the disenfranchised and lower classes and helped turn Turkey into a world power. That is one reason he is worshipped.

Read more: This North Korea propaganda newspaper reveals what Kim Jong-un really thinks

As mayor, he wore his ideology lightly and was an efficient technocrat who modernised Istanbul's infrastructure and fought pollution and traffic. After AKP (Justice & Development Party, founded by Erdogan in 2001) swept to power in 2002, it continued a series of IMF-led economic reforms, turning Turkey into a fast-emerging market. In recent years, growth has stalled, inflation jumped and an absence of structural reforms has made Turkey heavily dependent on foreign investment and vulnerable to economic crises. But Erdogan's supporters don't blame him.

"There are mountains of difference between the old and the new Turkey," says Morat Toprak, a school teacher who has a cast on one hand after fighting with a coup soldier. When he tried to grab the soldier's gun, his finger got caught and broke. "Turkey has grown like the Himalayas," he says.

To Erdogan's loyalists, the president is also a champion of democracy. Erdogan and AKP have won resounding victories in a string of multiparty elections. And the larger space he has carved out for Islam in Turkish society is, for many, not a step towards Islamisation but towards religious freedom. For instance, in a country where 97.8 per cent identify as Muslim, he lifted a long-standing ban on Islamic headscarves in public institutions, including most universities. That is a second reason a majority of Turks vote for him.

"Turks have not become more Islamic. We just have a leader who protects Islam," says a protester, Yahya Baris, 21. His friend, a sociology student named Esra, agrees. "He has given us more freedom," she says.

'We're not more Islamic. We just have a leader who protects Islam'

Few Erdogan supporters I speak to seem to care much for AKP. They back Erdogan. He is the party. It's as if he has cast a legion of devotees in the mould of his notorious poetry recital. As 26-year-old Ibrahim puts it, "We are the real soldiers."

One late afternoon, I meet Hakan Sivri, 36, outside his carwash. On coup night, he paid a greater sacrifice than most. He saw a man get shot in the chest and held him as he died. Minutes later, a friend called to tell Sivri that his brother had also been shot. He raced with the ambulance to the hospital, but in the early morning hours, he lost his brother. Sivri tells his story as the sun sets over the Bosphorus Bridge, enveloping one side of his face in an amber light. He holds it together pretty well.

"My brother was a strong nationalist," he says. For his whole family, Erdogan is a paragon of progress. "Our country is going to be a big, powerful country, be sure of that," Sivri says. He thinks the coup was a conspiracy between "Gulen, CIA, FBI, Mossad. There are many that have an eye on our country. If Erdogan had been killed, the US would have invaded the country in the name of peace."

Erdogan is also a link to a golden age, a time sepia-tinted by nationalist nostalgia, when Turks ran an entire empire. As we say our goodbyes, Sivri gives me his phone number. He waited to get that number for months because he wanted one that ended in "1453": the year the Ottoman army conquered Constantinople (now Istanbul) from the Byzantine Empire.

In the days after they thwarted the coup, pro-Erdogan protesters are like football fans whose team have thrashed an arch rival. They gloat aggressively. Turkish flags are everywhere, fluttering on the façades of high rises and in the hands of thousands of people in squares, where entertainers and pop stars are whipping the crowd into a frenzy. In Istiklal, the main shopping street, hordes of young men and women carry banners the size of the ferries that sail up and down the Golden Horn, brandishing the president's face and shouting: "Ya Allah, Bismillah, Allahu Akbar!" ("Oh God, in God's name, God is great.")

It is midnight and down an alley, in an outdoor teahouse, a group of friends are eating grilled cheese sandwiches. They are not Erdogan fans. "This is not a victory party," says one of them, Ismail Kaya. More than 200 of their fellow countrymen have been killed and we all should be mourning, he says. All the friends were fiercely against any coup attempt, but they don't want to partake in a celebration alongside Erdogan's supporters. Bilal Seckin, a journalist, agrees with the football analogy, and has coined a term for how Turkish politics has changed: "The population has been hooliganised," he says.

A week later, I attend another rally, in front of Erdogan's house in a neighbourhood called Kisikli. Here are thousands of people, wearing red Erdogan football jerseys and scarves with Erdogan's face on them, Erdogan flags and women in black full-body carsafs (the Turkish niqab) sporting Erdogan headbands. The crowd is a sea of flags, the ground a torrent of strollers. It's a family event. On stage, an orchestra called the Ottoman Military Band is playing a song called "Attack March". Another song goes: "God is great, God is great, God is great, Turks are coming." It has now been 12 days since the coup attempt and the party is unrelenting. A big screen shows fighting from the bridge on coup night, complete with piercing bursts of gunfire that startle people. Maybe not the best thing in a city already jarred by monthly terrorist attacks.

In the queue for free food I meet two young men who were on the bridge that night. Ali looks like he was athletic once. Nihat, portly and bearded, never was. "Beating the soldiers on the bridge was the right thing to do," Ali says. As for the claims that detainees have been abused in prisons? "If you don't beat them and torture them, they won't talk. They have been brainwashed by Gulen," he says.

Whether Gulen masterminded the coup or not, his ability to do so is not entirely a figment of Erdogan's imagination. Gulen, who was Erdogan's ally until they fell out in 2013, heads an Islamic order so big it is second only to the Muslim Brotherhood in global reach. It runs schools in more than 130 countries, and he is thought to have between two and three million followers in Turkey, including parliamentarians and members of the security forces. He has been in self-imposed exile in Pennsylvania since 1999, has denied any involvement in the coup and the US has so far not found the evidence persuasive enough to extradite him, but that doesn't assuage people here.

"If he wants to fight against us, he should have the balls to come home and face a woman like me," yells 30-something Huriye Demirel, before she plunges into the crowd with a lit Roman candle in each hand.

While the post-coup crackdown has been extraordinary in scope, Erdogan's totalitarian bent is not new. From 2007 to 2012, the government arrested more than 700 people, including army officers, parliamentarians, journalists, NGO-workers and university officials. Before the coup attempt, about 15 per cent of admirals and generals in the armed forces were on trial for colluding to overthrow the government.

The post-coup purge seems so in line with Erdogan's previous policies that some, including Gulen, have speculated that the president staged it himself. Why didn't the plotters shoot down Erdogan's plane when they had the chance? Why were they an hour late when raiding his beachside hotel earlier that evening? Why did the coup attempt begin in the evening when plenty of people were in the street and not later when it might have succeeded? Add to that Erdogan's own statement after the coup: "This uprising is a gift from God to us because this will be a reason to cleanse our army."

'The European Union thinks they have us on a leash like a dog'

However, no proof has emerged of such a conspiracy. None of the military officers arrested after the coup were Erdogan allies. Quite the contrary. What seems more likely is that some military officers seized a last-ditch chance to save their own skin. In August, the Turkish military was due to go through its annual shake-up, where many Gulen supporters were expected to be replaced. Indeed, the poor execution of the coup might be a sign of the loss of competent people that has already taken place in the army.

Meanwhile, even though Erdogan began his clampdown on the opposition at least ten years ago, the bar for what can get you into trouble seems to be lowering.

Until recently, Istar Gozaydin headed the department of sociology at Gediz University. When I meet her, she has sheltered herself in her apartment for a week, with piles of books, metres of classical music and her husband and cats. Days after the coup, she was suspended. The reason, she says, was not something she said, but merely something she retweeted: photos of violence in the coup aftermath and condemnations of capital punishment. She has no connection to Gulen, she says, with a scoff, but in the post-coup witch-hunt, institutions were trying to get rid of anyone that might turn them into a target. By suspending her, "the university was trying to protect itself", Gozaydin says. Nevertheless, days later, the government closed the university, along with more than a dozen others.

"I am who I am. I defend whatever I think is right," she says. She is senior enough not to worry about her future, she claims, but for younger professors and students affected by school closures, difficult times are ahead. "I'm really anxious about the young ones," she says.

Read more: Donald Trump's Syria airstrikes are damaging to US-Russia relations

The crackdown has fractured an already divided Turkish society in a way experts worry could cause long-term damage. Lisel Hintz, assistant visiting professor at Barnard College in New York, says Erdogan uses "rhetorical vilification" of opponents, to "switch on" and mobilise his supporters. "Not unlike Donald Trump," she adds.

"What's really scary to me is that there's nothing inherently violent in Islam, but [Erdogan] uses Islam in a polarising way... He says, 'We are the pure, and they are trying to destroy what we have and impede our progress. You need to go out and take the country back from them.'"

To locate the source of the gushing spring that is Erdogan devotion, I go to Kasimpasa, a poor neighbourhood spread out over steep hills. This is where the Erdogan family moved from the Black Sea town of Rize and where the young Tayyip grew up, peddling bread rolls in the street. Banners here greet the president in the informal way you address a neighbourhood son: "Tayyip Abi" or "Brother Tayyip".

Erdogan grew up in a modest six-storey building, where residents on the top floors get their groceries from the local corner store in a basket tied to a rope. On the third floor, Umnuhan Engin, 54, invites me in. She has bleached hair, no headscarf and wears custard-coloured nail polish on her toes. Every time she removes a slim Winner cigarette from her lips to put it out, it is promptly replaced by a new one.

On the wall is a mid-Nineties photo of her ageing mother - who listens in from her seat on the other couch - hugging Erdogan. At that time, he had abandoned a career as a scrappy footballer to become Istanbul's mayor and still sported the moustache that got him fired in the early Eighties from Istanbul's transport authority because he refused to shave it off.

Read more: After Brexit, EU citizens must be allowed to stay

In Kasimpasa, Erdogan is the stuff of lore. He brought the neighbourhood drinking water and good roads, stopped crime and stood up to arrogant foreign powers and often visited his mother when she was still alive. When he did, he made sure to knock on the old ladies' doors every time he went to the store to check on them. Those who tried to unseat him should be punished by death, Umnuhan says, even if the EU has threatened that reinstating capital punishment would jeopardise Turkish membership. Umnuhan grows more agitated with every question, with every cigarette inhaled violently.

"We don't care about the EU or the United States," she says. "The American police are killing people in the street. Do we say anything to them? The US has the electric chair, what kind of democracy is that?"

"They cannot take Erdogan down," she says. "He is like a miracle."

Almost every Erdogan loyalist I speak to says the government should arrest more dissidents than it already has. One of those swept up in the purge is Orhan Kemal Cengiz, a prominent journalist and human rights lawyer. Days after the coup attempt, he was on his way to a conference abroad when immigration officers at the airport detained him.

Cengiz represented Zaman, a large newspaper financed by Gulen, when it was seized in March as part of a crackdown on the press. Cengiz denies being a Gulenist. Over the years, he says, he has represented Kurdish PKK militants, religious minorities and Islamic institutions. "This is the first time I have ever been associated with the people I represent," he says. Cengiz also wrote a column for Zaman, but he says he chose the outlet not because of its political leanings, but because "Recep Tayyip Erdogan didn't leave us many other options".

Cengiz was released after a week, but is banned from travelling. "I don't know if it's the end of the story," he says. For Cengiz, the clampdown on media is a serious stain on Turkey's self-portrayal as a modern democracy. He concedes that the government is elected by the people. "But what are elections without a free press? I respect the nation's will but the nation's will should be formed in a free manner," he says. "[After the failed coup] they said democracy won, but all democrats are worried," he says.

A case in point is that people from one of the most potent pro-democracy movements in recent Turkish history have been conspicuously absent from the anti-coup rallies.

Akif Burak Atlar was part of the core in the Gezi demonstrations in 2013. The movement began as a protest against an urban development plan, but evolved into Turkey's version of Occupy Wall Street. As the movement was suppressed with violence, it became a symbol of pro-democracy and secularism.

Atlar, who is also secretary of Istanbul's Chamber Of Urban Planners, was charged with being a member of a terrorist organisation. It took him two years of trial to get cleared. I ask him why I haven't found any Gezi protesters opposing the coup, which most of them agree was an affront to Turkey's democracy.

'Speaking to Atlar, I get the sense that Erdogan has won. At least when it comes to suppressing dissent from young, liberal secularists like him.'

"I don't know," he says. "But personally, I wouldn't feel comfortable in a protest that has religious origins and giving support to the political side of the president," he says. It is not as if Atlar supported the coup. He is so anti-military that in the past he took a $10,000 loan to buy his way out of military service. But the pro-Erdogan demonstrations are aggressively biased and, he says, have taken a chunk out of the symbolic turf the Gezi movement managed to claim. Until 15 July, it had been illegal to gather even in small groups at Taksim Square, which became synonymous with the Gezi protests. That ban has been ignored for Erdogan's supporters, effectively giving them a symbolic, if temporary, ownership of the square.

Speaking to Atlar, I get the sense that Erdogan has won. At least when it comes to suppressing dissent from young, liberal secularists like him.

"People are afraid now that in this state of emergency, there will be a criminalisation of people who have nothing to do with this attempt, but who just criticise the government." The protest movement is, if not dead, still licking its wounds.

"People have had enough of tear gas and police violence," Atlar says.

After the coup attempt, Erdogan called for a three-month state of emergency. That period, which could extend in case of another terrorist attack, may provide an opportunity for Erdogan to pursue his ambition to create a system that concentrates more power in the hands of the president. He has already issued decrees giving the president and prime minister authority to make direct orders to military commanders, closed military schools and put the health ministry in charge of military hospitals.

While the failed coup allowed Erdogan to tighten his grip on the country, it also showed that perhaps he wasn't as strong as he imagined. Turkey is under tremendous pressure from the war in neighbouring Syria and a wave of deadly Isis attacks. Erdogan has been welcoming to Syrian refugees but, with at least 2.5 million of them, the stagnant Turkish economy is groaning.

The refugees have not just transformed Turkey but also its relationship with the EU, which finds itself severely dependent on Turkey to solve the challenge of the many Syrians seeking new lives in Europe.

The EU has criticised Erdogan's post-coup crackdown, with its foreign policy chief, Federica Mogherini, saying that, "We need to have Turkey respect democracy, human rights and fundamental freedoms." For his part, Erdogan has lashed out at the EU for not condemning the coup harshly enough and for failing to pay him a visit afterwards. Ultimately, the mutual dependency is probably too great for the process of Turkish EU membership to implode completely, but at the moment, the relationship is in a tailspin.

To many Turks, the EU's criticism is just another example of patronising double standards. Turkey has been promised a path to EU membership since 1963, but the EU has, in the eyes of many Turks, reneged on its promises, even though Turkey is a dramatically reformed country.

"They have been keeping Turkey waiting at their door for 53 years," Erdogan said in June, echoing a common sentiment among his voters.

"EU is always meddling," says Gamsiz, the teacher at Taksim. "EU is a big liar. EU doesn't want Turkey."

For now, a considerable part of the Turkish population seems happy to leave Erdogan to assume greater powers in his defence of the state. They continue to rally behind him. On my last night in Istanbul, I visit a mosque in central Uskudar, a block from where tanks rumbled through the streets two weeks earlier. Before the prayer, the imam implores believers to resist those who want to "seize" and "destroy the country". Below the golden-lit arches, as midnight approaches, the young faithful are preparing to sit the night watch outside the mosque. If anyone tries another coup, they will be prepared, and practised.

Originally published in December 2016 issue of British GQ