The deadly coup attempt in July 2016 marked a monumental turning point in Turkey's political history. But six months on, for many people outside Turkey, it is still not clear exactly how and by whom this coup attempt was organised and what it means for Turkey.
Al Jazeera explains who was responsible, what happened and why.
| What happened that night?
Turkey witnessed the bloodiest coup attempt in its political history on July 15, 2016, when a section of the Turkish military launched a coordinated operation in several major cities to topple the government and unseat President Recep Tayyip Erdogan.
Soldiers and tanks took to the streets and a number of explosions rang out in Ankara and Istanbul.
READ MORE: Turkey timeline - Here's how the coup attempt unfolded
Turkish fighter jets dropped bombs on their own parliament, while the chairman of the Joint Chiefs of Staff, Hulusi Akar, was kidnapped by his own security detail.
For several hours, it looked like Turkey was going to face the fourth devastating military coup in its 95-year political history.
But at this point, something unprecedented happened.
|Thousands of ordinary citizens took to the streets to oppose the attempted coup on July 15 [Tolga Bozoglu/EPA]
As news of the coup attempt spread via social media, thousands of ordinary citizens, armed with nothing more than kitchen utensils, gathered in streets and squares around Anatolia to oppose the coup.
The crowds resisted tank fire and air bombardments and, with the help of loyalist soldiers and police forces, they defeated the coup attempt in a matter of hours. The government swiftly declared victory and scores of troops that had taken part in the coup surrendered on the Bosphorus Bridge in Istanbul.
Yet the overall price of victory was high: 241 people were killed and 2,194 others were injured.
The Turkish government blames the failed coup attempt on Fethullah Gulen, a Turkish preacher and businessman who has lived in self-imposed exile in the United States since 1999.
Gulen is the leader of a widespread and influential religious movement known as "Hizmet" (Sevice), which owns foundations, associations, media organisations and schools in Turkey and abroad.
READ MORE: Turkish minister - Fethullah Gulen is our Bin Laden
Gulen was once a strong ally of Erdogan, and during the Justice and Development Party (AKP) struggle to end the military's influence in Turkish politics in the late 2000s, his organisation had its golden years.
During this period, the AKP-Gulen alliance turned into direct staffing of public positions. Many people in the bureaucracy were removed without due process and replaced with Gulenists.
|US-based cleric Fethullah Gulen at his home in Saylorsburg, Pennsylvania [Charles Mostoller/Reuters]
Yet the Gulen-AKP relationship was eroded by incidents such as the 2010 Mavi Marmara raid, and by National Intelligence Organisation (MIT) Undersecretary Hakan Fidan, a close Erdogan confidant, being called in for questioning by police officers close to the Gulen movement.
A corruption investigation in December 2013, which saw renowned business people and senior bureaucrats close to the AKP arrested by Gulenist police officers, gave way to an all-out war between the government and the Hizmet movement.
OPINION: The Gulen organisation's long journey
Erdogan reacted furiously to the crackdown and claimed that those behind the investigations were trying to form a "state within a state", in an apparent reference to the Hizmet movement.
From this point on, the AKP government was always open about its plans to eradicate Gulen and his followers from Turkish political life, as the MIT conducted several investigations into Gulen and his followers.
Today, Turkish officials say that the July coup attempt materialised because Gulenists were increasingly concerned that the government investigation into their illegal actions was coming to an end, and they would be arrested.
Gulen, on the other hand, denies any role in the coup and has even alleged that Erdogan orchestrated it himself "to build a dictatorship" - a claim the president, Turkish spy agencies and even the Turkish opposition have vehemently denied.
| How did Turkey's National Intelligence Organisation miss the signs of the looming insurrection?
July's coup attempt has given rise to serious questions about Turkey's intelligence capabilities.
In the aftermath of the coup attempt, MIT officials admitted that they received the very first intelligence report about a possible attack on July 15, only hours before their own headquarters was under heavy artillery fire.
They also admitted that the undersecretary of the MIT tried to reach Erdogan to inform him about this initial report around 7pm local time, but failed to get him on the phone.
READ MORE: Unanswered questions on Turkey's failed coup attempt
Why the undersecretary did not call Prime Minister Binali Yildirim after he failed to reach the president is another unanswered question about that night.
In a televised interview after the coup attempt, Yildirim said: "I asked the undersecretary of the MIT about this matter but I could not get a satisfactory answer."
In an exclusive Al Jazeera interview, Erdogan also admitted that Turkey experienced some intelligence failures on July 15.
He said that he had learned about the extraordinary developments taking place in Ankara and Istanbul on the night of the coup attempt not from the MIT, but from his brother-in-law.
IN PICTURES: Erdogan supporters on the streets of Turkey
Intelligence officials said that in the months before the failed coup attempt, the country's spy agency decoded millions of secret messages sent by suspected Gulenists, but found no mention of the plot.
Six months on, it is still not entirely clear how the MIT failed to detect the preparations for the coup attempt and why it failed to notify the president or the prime minister immediately once they received intelligence on the plot.
| How did the Turkish government respond to the failed coup attempt?
Only days after the coup attempt, on July 22, the Turkish government declared a state of emergency "to be able to remove swiftly all the elements of the terrorist organisation involved in the coup attempt".
|Thousands were arrested after the failed coup attempt [Sedat Suna/EPA]
In the following weeks, Turkish courts placed tens of thousands of suspects under arrest on charges of links to Gulen.
Thousands of military officials, pilots, police officers, civil servants, academics and even teachers were sacked from their jobs for alleged links to the "terrorist" preacher and his movement.
Dozens of media outlets suspected of having links to the Hizmet movement were also shut down.
As of today, more than 100,000 people have been sacked or suspended and 37,000 arrested in an unprecedented crackdown. The government has deemed the crackdown necessary to "root out all coup supporters from the state apparatus".
In another move, the ability of universities to elect their own rectors was also abolished. Erdogan will now directly appoint nominees.
| How did the Turkish government determine who to detain or sack in such a short time?
Many people questioned how the Turkish government managed to determine the names of tens of thousands of people with alleged links to the Hizmet movement only days after the attempted coup.
Turkish officials say that they were able to act swiftly because intelligence agencies had been investigating Gulen and his followers for more than two years.
READ MORE: Turkey - Government launches purge after attempted coup
Although there is no confirmed public information, according to several Turkish media reports it seems that the MIT shared noteworthy information about the Gulen organisation with state units from 2014.
For example, speaking to Turkey's state-run Anadolu Agency in May 2015 about the Gulenists within the Turkish armed forces, Former Minister of Defence Ismet Yildiz said: "So far we have received reports of more than 1,000 people from Turkish armed forces."
Days later, Sertac Es, a journalist from the daily Cumhuriyet, reported that the MIT had sent the General Staff an extended list of Gulenists within the military, citing defence ministry sources.
"According to the information received from defence ministry sources, the MIT had sent the General Staff a list of 1,200 people who are considered to be members of the Gulen organisation, including two generals," he said.
READ MORE: Turkey - Coup plotters 'acted early' in fear of arrests
But the most critical move by the MIT leading to the state's quick reaction to the coup attempt was the uncovering of the group's communication system, according to Turkish officials.
The information so far indicates that Gulenists have been using an encoded communication application called Bylock since 2014. The MIT noticed and decoded Bylock in 2015. At that point, the movement started using another encoded application for communication named Eagle.
As a result of these investigations, it is believed that the MIT got together an extensive list of at least 40,000 suspected Gulenists, including 600 high-ranking officials.
According to officials, these lists were used to determine the names that would be detained or sacked after the coup attempt.
| How did the coup attempt affect Turkey's relations with other countries?
The post-coup purge led to a rift in Turkey's relations with the European Union, which accused Erdogan of using the coup attempt as an excuse to eliminate the opposition.
Turkey's relations with the US also deteriorated as a result of this incident, as Washington refused to extradite Gulen.
READ MORE: Turkey coup attempt - Reaction from around the world
The Turkish Justice Ministry formally demanded in September that US authorities arrest Gulen on charges of "ordering and commanding the attempted coup". But to this day, US authorities insist that they do not have enough evidence to arrest Gulen or to start the formal process for his extradition.
US Defence Secretary Ash Carter, with Turkey's Defence Minister Fikri Isik, in October visited the Turkish parliament, which was partly damaged in the coup attempt [Adem Altan/Reuters]
In a statement to Al Jazeera in late August, Yasin Aktay, the deputy chairman of the ruling AKP, said that Washington's reluctance to return Gulen to Turkey, or to arrest him, was unacceptable.
"It is bizarre for us that they [the US] have not been convinced, considering the scope of evidence we presented to them," Aktay said. "The testimony of the suspects who were arrested red-handed and documents we gave them are clear. If you add the statements of Gulen regarding the goal of his organisational movement, we believe there is nothing to question. Strong American intelligence should be well aware of who he really is."
While the coup attempt, and the government's harsh response to it, led to a serious rift in Turkey's relations with its western allies, the incident brought Turkish political parties closer, at least for a short while.
A day after Turkey's failed coup attempt, all major political parties united against the "unparalleled attack on the Turkish democracy", issuing a joint declaration to condemn it.
"Faced with the threat of a Gulenist coup, everyone left aside their political differences and joined hands to make sure that never again will the people be stripped of their right to choose their leaders," a senior government official told Al Jazeera.
READ MORE: How could failed coup affect Kurdish peace process?
Erdogan also put aside acrimony with the leaders of two opposition parties, inviting them to the presidential palace for talks in a gesture of national unity.
The only group that was not included in the newly found spirit of solidarity was Turkey's Kurds. The leader of the pro-Kurdish Peoples' Democratic Party, Selahattin Demirtas, was excluded from the post-coup talks on the grounds that his party allegedly supports the outlawed Kurdistan Workers' Party (PKK).
Later, the government used the state of emergency to shut down several pro-Kurdish media organisations and arrest Kurdish journalists and civil servants for their alleged links to the PKK.
Source: Al Jazeera