Last Friday at 8 p.m., rogue elements within the Turkish army launched a violent bid to remove the AKP government and President Recep Tayyip Erdoğan from power.

The first signs that something was amiss came after an hour and a half. Reports began to circulate of soldiers in tanks blocking the two bridges over the Bosphorus in Istanbul. Shortly thereafter, around a dozen F16 fighter jets were seen flying low in the skies above the capital, Ankara.

At 10 p.m. the country’s Prime Minister, Binali Yildirim, announced what many feared: The country was undergoing unlawful “military activity.” A coup d’état was in progress. Soon bombs began falling on government buildings in the capital, and soldiers exchanged gunfire with police in both Ankara and Istanbul.

Despite the might of the Turkish armed forces – ninth largest in the world – the government needed only a few hours to subdue the attack. By the morning, it was clear why that was: The failed coup lacked full military support. Footage of young soldiers abandoning their tanks on the Bosphorus Bridge, arms raised to surrender, marked the end of a dark night in Turkey.

According to official sources, 1,535 people were injured and another 250 killed: 173 civilians, 62 police officers, and five soldiers. The exact number of coupists killed is unknown – the government didn’t include them in its official death toll.

But who was behind it? Turkish authorities have already begun cracking down on those it claimed were responsible: members of an alleged secret, parallel state headed by Erdoğan nemesis and exiled-preacher, Fethullah Gülen.

Why the coup took place earlier than expected

But before we go into that, there’s another matter: Intelligence officials told journalists that at around 4 p.m. Friday, senior MIT officers learned that elements within the army were preparing a military coup set for 3 a.m. the next morning. The intelligence service immediately informed the government.

At 5:30 p.m. that same evening, the Head of MIT, Hakan Fidan – an Erdoğan stalwart – met with army and other state officials at the military’s headquarters in Istanbul.

The announcement inevitably made its way to the putschists, who then decided to commence the operation earlier than planned

During the 30-minute meeting, Fidan, Army Chief of Staff Hulusi Akar, his second-in-command Yasar Güler, and Head of Turkish Land Forces Salih Zeki Çolak, formulated a plan to stop the anticipated attack.

At 6 p.m. orders were sent to every member of the armed forces across Turkey, banning all military flights and movement of personnel and tanks. The directive also stated that generals would be inspecting army training schools.

The announcement inevitably made its way to the putschists, who then decided to commence the operation earlier than planned, on Friday evening instead of the early hours of Saturday.

So who were these coup plotters?

Were Gülen supporters behind the coup? There was certainly growing hostility between Erdoğan and Gülenists within the army.

Pro-Erdogan supporters hold up an effigy of Islamic cleric Fethullah Gülen during a demonstration at Taksim Square in Istanbul on July 18, 2016. Photo by Ozan Kose / AFP

Pro-Erdogan supporters hold up an effigy of Islamic cleric Fethullah Gülen during a demonstration at Taksim Square in Istanbul on July 18, 2016. Photo by Ozan Kose / AFP

One reason for this was the president’s plans to use the Supreme Military Council meeting on August 1 to cleanse it of the influence of Cemaat – another name for Gülen’s movement. The Council convenes twice a year to determine the army’s priorities and promote or demote officers, and Gülenists were to be the main target.

The other reason that hostility between both camps was on the rise lately has its roots in an espionage case in the western city of Izmir. In February this year, the Izmir court acquitted over 350 military officials accused of accessing classified national security documents. The government claimed that the espionage trial, which began in 2012, was orchestrated by pro-Gülen forces determined to weaken the AKP.

Then on July 9, İzmir Deputy Chief Prosecutor Okan Bato, head of the Terror and Organized Crimes Investigation Bureau, brought charges against several military personnel accused of forging legal evidence during the trial and being members of the Fethullahist Terrorist Organization/Parallel State Structure – the same organization said to be behind last Friday’s coup. They would, he said, be the first of many upcoming arrests.

The Cemaat cadre in the military then got wind of security service plans to conduct 4 a.m. raids against hundreds of soldiers on Saturday. Facing the possibility of life in prison either way, the decision was made to launch the coup before arrests could be carried out.

How the state responded to the coup attempt

What happened after the coup attempt? The state’s crackdown on those it claims are responsible has been fierce. Even before the sun rose in Turkey, members of the security services were rounding up thousands of the country’s military officials, soldiers, and judges – followers, they say, of Gülen.

In the days since the failed coup, some 52,000 civil servants have been arrested, suspended, or detained, as well as at least 3,000 soldiers, including 118 high ranking military officials, and more than 3,000 judges and prosecutors.

Erdoğan also called for Gülen’s extradition from the U.S. even as the cleric denies accusations he was behind the coup.

In the days since the failed coup, some 52,000 civil servants have been arrested, suspended, or detained

The man accused of orchestrating the plot, General Akin Ozturk, former commander of the air force, was arrested for treason on Monday, along with 100 other senior personnel. Ozturk denies any involvement.

Already, between 8,000 and 9,000 have been dismissed from the state security institutions, including the police, gendarmerie, and MIT. The Higher Education Council has requested the resignation of 15,200 staff from the education ministry, including 1,577 university deans, and 21,000 private school teachers have had their licenses revoked. A further 492 from the finance ministry and 257 workers in the Prime Minister’s office have been fired, and nearly 500 clerics and religious teachers have been dismissed.

Erdoğan has faced criticism from politicians and diplomats concerned he is exploiting the coup to rid Turkey’s institutions of not only the Gülen elements, but of all opposition.

On Monday, EU Enlargement Commissioner Johannes Hahn told the European Council that he believed the state had lists of those it wished to arrest “available already after the event, this indicates that this was prepared to be used at a certain stage”.

How the AKP and the Gülen movement are interconnected

To understand these recent events, a brief history of the ties between Erdoğan and Gülen is in order.

Erdoğan and fellow politician Abdullah Gül founded the Justice and Development Party, or the AKP, in 2001 in order to contest the general election the following year. By then, Gülen had been in self-imposed exile in the U.S. for two years, fleeing charges of conspiring to overthrow Turkey’s secular state brought against him by the military.

From a compound in Pennsylvania, Gülen was operating hundreds of religious schools in Turkey and across the world. His private education institutions provided him with billions of dollars and millions of loyal followers, from ordinary citizens to academics, prominent businessmen, law enforcement agents, and journalists.

Pro-Erdogan supporters wave flags during a demonstration at Taksim Square on July 20, 2016 in Istanbul. Photo by Ammar Awad / Reuters

Pro-Erdogan supporters wave flags during a demonstration at Taksim Square on July 20, 2016 in Istanbul. Photo by Ammar Awad / Reuters

During the AKP’s first national election campaign, Gülen allowed his followers to freely vote as they saw fit. He was aware of the AKP’s popularity, and was reluctant to oppose them.

The AKP did indeed win the election, and in 2003 Erdoğan became prime minister. He was hailed by leaders in the West as being a Muslim for the 21st century: Islamic, but pro-democracy.

Since many of the AKP’s officials had defected from the explicitly religious Welfare Party, Erdoğan was forced to reassure Turkey’s military chiefs that the new government was genuinely secular.

For his first years in power, Erdoğan both remained the darling of the West by enacting several democratic reforms and maintained good relations with the military. But by 2007, his attitude had changed. Fatigued by the delays over Turkey’s accession to the EU – largely viewed by Turks as being motivated by European racism – Erdoğan had started adopting a more authoritarian attitude.

Despite the presidency being at the time a mostly ceremonial position, the Turkish military released a statement on its website expressing concerns about the pro-religious positions of Abdullah Gül, the AKP’s candidate in the 2007 election. The threat of a coup was not subtle.

Erdoğan saw this “e-coup” as confirmation that an alliance with the army was not possible, and he began to turn towards Fethullah Gülen and his followers to help cleanse the army and Turkey’s democratic institutions of secular Kemalists.

Gülen’s movement became an unofficial government partner. They were a significant power source for the AKP. As a gift to Gülen, the AKP eventually overturned his 2001 conspiracy conviction.

Over the next few years, Erdoğan helped Gülen strengthen his grip on Turkey’s institutions, engineering the appointment of his followers to prominent roles within the army, security services, and judiciary.

In return, Gülenists used their increasing power support Erdoğan’s campaign, which involved the illegal jailing of hundreds of military officials, members of the judiciary, and opposition journalists.

Gülen’s cadre of police and judges help arrest and charge the alleged Ergenekon members, and journalists at the Zaman newspaper – the country’s largest daily, which was recently taken over by the AKP – wrote stories supporting the accusations.

Although Ergenekon’s existence would later be largely discredited, Erdoğan and Gülen were successfully taking over Turkey’s democratic institutions.

An effigy of Islamic cleric Fethullah Gülen gets dragged along the ground at Atatürk National Airport in Istanbul on July 17, 2016. Photo by Berk Ozkan / Anadou

An effigy of Islamic cleric Fethullah Gülen gets dragged along the ground at Atatürk National Airport in Istanbul on July 17, 2016. Photo by Berk Ozkan / Anadou

And how the AKP and the Gülen movement became rivals

Their partnership would not last long, however. And events in late 2013 made it clear in a very public way that the fallout would not be pretty.

On December 17, 2013, the Turkish government was rocked by a corruption scandal involving several prominent businessmen and senior AKP ministers and their families, including Erdoğan.

Police and prosecutors detained nearly 100 people on suspicion of bribery, fraud, and money laundering. Simultaneously, recordings of the alleged malfeasance began appearing on YouTube, including incriminating conversations between Erdoğan and members of his family.

Conversations between Hakan Fidan, Yasar Güler, and former prime minister Ahmet Davutoğlu – foreign minister at the time – were also leaked, where they discussed staging a false flag operation in Syria to provide the casus belli Erdogan needed to go to war with Bashar al-Assad.

The source of the leaks? The Cemaat. The hidden presence of Cemaat in Turkey’s political system, allowed them to bug officials and decrypt phone calls. It had almost destroyed the AKP.

The government’s response was fierce. Laws were enacted to protect politicians, and thousands of the police and prosecutors involved in the corruption probe were arrested or demoted.

The AKP also thought up a new name for their rivals, the Fethullahist Terrorist Organization/Parallel State Structure (FETÖ/PDY), and then designated it an official enemy of the state.

The fallout from the corruption scandal was the first real evidence of a political war which had been raging in secret for nearly two years

The fallout from the corruption scandal was the first real evidence of a political war which had been raging in secret for nearly two years. Already in 2011, the AKP was considering closing many of Gülen’s “Hizmet” schools in Turkey. The 300 or so institutions provide the cleric with an important source of both cash and human capital, and he knew their closure would pose a significant threat to his influence.

Gülen responded aggressively. On February 7, 2012, the Cemaat released a tape online of secret discussions between MIT and jailed leader Abdullah Öcalan. For months, MIT had denied that talks were underway. But the recording proved the existence of the negotiations, showing Hakan Fidan, who was not yet officially appointed as the head of MIT, claiming that he represented Erdoğan in the meetings.

MIT immediately launched an ongoing investigation into the Cemaat. Things turned ugly very quickly.

A few days after the tapes leaked, prosecutors close to Gülen accused the five MIT members involved in the peace talks of terrorism, demanding they turn themselves in to the police.

When the men refused, police officers arrived at their homes at midnight to take them into custody. The government was forced to step in, instructing the agents to refuse to cooperate. The police and prosecutor, Sadrettin Sarikaya, were forced to back down.

Soon after, Sarikaya was dismissed from his post and the AKP enacted a law providing immunity to all MIT personnel.

It’s not clear why Gülen thought his 2012 attack on the government was a good idea, but the alliance was broken. A battle was in motion that would eventually result in bombs hitting the parliamentary building in Ankara some four-and-a-half years later.

Protesters burn an effigy of the Islamic cleric Fethullah Gülen during a demonstration at Taksim Square in Istanbul on 18 July 2016. Photo: Ozan Kose / AFP

Protesters burn an effigy of the Islamic cleric Fethullah Gülen during a demonstration at Taksim Square in Istanbul on 18 July 2016. Photo: Ozan Kose / AFP

What now?

We already mentioned the numerous civil servants that were rounded up by Turkish police following Friday’s failed coup. This group included thousands of the country’s prosecutors and judges. That’s striking, as members of the courts had little if any practical role in the operation, and many are questioning how it’s possible for Erdoğan to so quickly identify his Gülen enemies.

But, of course, as EU Commissioner Hahn posited, they already had their lists.

In 2014, following the corruption scandal, Erdoğan intended to cleanse the judiciary of the thousands of Gülenists that had joined its ranks. Four years earlier, the AKP had gifted a large portion of control to the Cemaat following a referendum to change the country’s constitution. The law expanded the number of seats on the HSYK, the Supreme Board of Judges and Prosecutors, and was designed to stack the judicial system with Cemaat and others loyal to Erdoğan.

The HSYK has significant powers to determine the politics of Turkey’s legal branch because its 22 members decide which prosecutors and judges are appointed. A majority of 12 effectively determines who runs Turkey’s courts system. In October 2014, the HSYK was to elect ten of its 22 members. And both Erdoğan and the Gülenists wanted control.

The two sides formed separate voting blocs. In total, over 12,000 judges and prosecutors voted, but in the end Erdoğan got his way.

It was this vote that provided the first statistical information about Cemaat presence within the justice system. Around 5,000 had supported Gülen’s cause by voting against the government candidates.

The state now had its list of political enemies to target.

On June 30, 2016, the Turkish parliament adopted a new law restructuring much of Turkey’s judicial system. Coming just one month after HSYK reassigned nearly 4,000 judges from other courts, the legislation provided the framework for the government to fire the 711 judges of the Council of State and the Supreme Court of Appeals – two of Turkey’s highest courts. President Erdoğan will now personally appoint one-third of the new judges, with the rest being named by HSYK.

The bill was criticised by some members of parliament, who accused the government of providing Erdoğan with power to remove all elements of opposition from the judiciary. But since the coup attempt last Friday, the government is now able to attack even those not directly involved in the coup with little opposition, capitalizing on the now rampant anti-Gülen sentiment in the country, and consolidating the president’s own grip on power in the process.

Protesters set alight an effigy of Islamic cleric Fethullah Gülen during a demonstration at Taksim Square in Istanbul on 18 July 2016. Photo: Ozan Kose / AFP

Protesters set alight an effigy of Islamic cleric Fethullah Gülen during a demonstration at Taksim Square in Istanbul on 18 July 2016. Photo: Ozan Kose / AFP

—This production was brokered by International Editor Maaike Goslinga. Journalist Zeynep Sentek also contributed to the story.

More from The Correspondent:

This is the Berlin Wall of our time Syrian refugees continue to flee the country in droves, but a solution to the conflict there remains elusive. Why? The answer may seem surprising, but our greatest obstacle on the road to peace in the world could well be veto rights in the United Nations. Read Maite’s story here Meet the most persecuted people in the world They survived ghettos, pogroms, slave ships, and torture camps. There’s a reason the UN calls them the most persecuted group in the world. And no, those causing the misery aren’t radical Muslims, but nationalist Buddhists. Photographer Andreas Stahl and I traveled to three countries to record the Rohingyas’ story – a story that can only be described as the chronicle of a genocide foretold. Read Lennart’s story here Never before was so much of the world fenced off by barbed wire Since its invention a century and a half ago, barbed wire has left a trail of blood in its wake. First developed to keep livestock in or out, it was swiftly put to use to divide humanity into the haves and the have nots. If Google Maps were honest, it would show barbed wire everywhere – in combat zones, along national borders, around ranches, schools, and prisons. For my recent book, I took a look at how things got to this point: a brief history of the Devil’s Rope. Read Dick’s story here