Following a failed coup against Turkish president Recep Tayyip Erdogan, the government moved swiftly to shore up his power and remove those perceived as an enemy, saying on Sunday it has detained 6,000 people.
The crackdown targeted not only generals and soldiers, but a wide swathe of the judiciary that has sometimes blocked Mr Erdogan, raising concerns that the effort to oust him will push Turkey even further into authoritarian rule.
Friday night's sudden uprising by a faction of the military appeared to take the government - and much of the world - by surprise.
The plotters sent warplanes firing on key government installations and tanks rolling into major cities, but it ended hours later when loyal government forces regained control of the military, and civilians took to the streets in support of Mr Erdogan. At least 294 people were killed and more than 1,400 wounded, the government said.
On Sunday, premier Binali Yildirim said the coup had failed and life has returned to normal.
"Another calamity has been thwarted," Mr Yildirim said in Ankara after visiting state TRT television, which had been seized by soldiers supporting the coup.
"However, our duty is not over. We shall rapidly conduct the cleansing operation so that they cannot again show the audacity of coming against the will of the people."
Mr Yildirim said those involved with the failed coup "will receive every punishment they deserve". Mr Erdogan suggested that Turkey might reinstate capital punishment, which was legally abolished in 2004 as part of the country's bid to join the European Union.
Speaking to a large crowd of his supporters in front of his Istanbul residence on Sunday evening, Mr Erdogan responded to frequent calls of "We want the death penalty!" by saying: "We hear your request. In a democracy, whatever the people want they will get."
Funerals were held for some of those who were killed in the coup attempt, including MR Erdogan's campaign manager Erol Olcak and his 16-year-old son, Abdullah Tayyip Olcak.
The president, who attended the service, wept and vowed to take the country forward in "unity and solidarity".
The government's announcement that 6,000 people had been detained - including three top generals and hundreds of soldiers - suggested a wide conspiracy.
Observers said the scale of the crackdown, especially against the judiciary, indicated the government was taking the opportunity to further consolidate Mr Erdogan's power.
"The factions within the military opposed to Erdogan who did this just gave him carte blanche to crack down not only on the military but on the judiciary," said Aykan Erdemir, a former politician from the main opposition party and now a senior fellow at the US-based Foundation for Defence of Democracies. "The coup plotters couldn't have helped Erdogan more."
Even before the chaos in Turkey, the Nato member and key Western ally in the fight against the Islamic State group had been wracked by political turmoil that critics blamed on Mr Erdogan's increasingly heavy-handed rule. He has shaken up the government, cracked down on dissent, restricted the media and renewed fighting with Kurdish rebels.
The rapid suppression of the putsch was greeted by Turks across the political spectrum with opposition parties joining quickly to condemn it. In a half-dozen cities, tens of thousands marched throughout the day after officials urged them to defend democracy and back Mr Erdogan, Turkey's top politician for 13 years.
At nightfall, flag-waving crowds rallied in Istanbul's Taksim Square, Ankara's Kizilay Square and elsewhere.
The Yeni Safak newspaper used the headline Traitors Of The Country, while the Hurriyet newspaper declared Democracy's Victory.
"Just a small group from Turkish armed forces stood up against our government ... but we, the Turkish nation, stand together and repulse it back," said Gozde Kurt, a 16-year-old student at a morning rally in Istanbul.
The failed coup and the subsequent crackdown followed moves by Mr Erdogan to reshape both the military and the judiciary. He had indicated a shake-up of the military was imminent and had also taken steps to increase his influence over the judiciary.
This month, parliament approved a controversial bill to reform two Turkish high courts, which allows the government to dismiss hundreds of administrative and high appeals court judges and allow Mr Erdogan to replace them with judges loyal to him. Parliament passed the bill even as authorities were grappling with a deadly triple suicide bomb attacks at Istanbul's Ataturk Airport.
The opposition had appealed against the legislation to the high court unsuccessfully, but Mr Erdogan has not yet signed it in to law. Two Constitutional Court justices were among the thousands of members of the judiciary it had detained on Saturday.
It is not clear what effect the post-coup purge will have on the judiciary, how the government will move to replace the dismissed judges and prosecutors, or where the trials for those detained would be held.
The government alleges that the coup conspirators were loyal to moderate US-based cleric Fethullah Gulen, whom Mr Erdogan has often accused of trying to overthrow the government.
Mr Gulen, who lives in Saylorsburgh, Pennsylvania, espouses a philosophy that blends a mystical form of Islam with democracy. He is a former Erdogan ally turned bitter foe who has been put on trial in absentia in Turkey, where the government has labelled his movement a terrorist organisation.
He strongly denies the government's charges.
In recent years, the government had already moved to purge the police and judiciary of Gulen followers. The military, founded on secularist ideals, has been a staunch opponent of Mr Gulen, and so far officials have not offered evidence that he was involved in the coup attempt.
Speaking at a funeral in Istanbul, Mr Erdogan vowed to "clean all state institutions of the virus" of Mr Gulen's supporters. He also called on Washington to extradite Mr Gulen.
At two weekend news conferences, Mr Gulen strongly denied any role in or knowledge of the coup.
"As someone who suffered under multiple military coups during the past five decades, it is especially insulting to be accused of having any link to such an attempt," he said.
He said he did not fear extradition.
"This doesn't worry me at all. But I'm not going to do anything that will harm my dignity or that will go against my dignity," he said.
US secretary of state John Kerry said the United States would entertain an extradition request for Mr Gulen, but Turkey would have to present "legitimate evidence that withstands scrutiny".
Ziya Meral of the Centre for Historial Analysis and Conflict Research, a civilian think tank affiliated with the British Defence Ministry, said the motives of the plotters remain unclear, but the allegations against Mr Gulen were dubious.
"I am more inclined toward a network within the armed services who were disturbed about where Turkey is heading," she said.
The allegations will only add to the pressure on the US government and signal new uncertainty in US-Turkish relations.
The putsch attempt led to a temporary halt to air operations by the US-led coalition against the Islamic State group in neighbouring Syria and Iraq from Turkey's Incerlik air base, but the Pentagon said on Sunday that Turkey has reopened its airspace.
A Turkish government official said that the commander of the base, General Bekir Ercan Van, was among those detained.
The state-run Anadolu Agency also said authorities have issued a warrant for the arrest of Mr Erdogan's top military aide, Colonel Ali Yazici, although it was not clear what role he may have played in the attempted coup.
The agency said 70 generals and admirals, including former General Akin Ozturk, an air Force commander, were detained in the investigation. Of the generals and admirals brought before court, 11 were put under arrest as of Sunday night and the rest are awaiting processing.
Security forces arrested a group of coup plotters who had been holding out at one of Istanbul's airports on Sunday, a Turkish official said. In addition, Anadolu reported that seven people, including a colonel, were detained at an air base in the central Anatolian city of Konya.
General Umit Dunda said at least 104 conspirators were among those killed, describing them as mainly officers from the air force, the military police and armoured units.
Security forces rounded up 52 more military officers for alleged links to the coup. Anadolu said a detention order has been issued for 110 judges and prosecutors in Istanbul alone for alleged involvement with the group responsible for the coup.
The suspects are being charged with "membership in an armed terrorist organisation" and "attempting to overthrow the government of the Turkish Republic using force and violence or attempting to completely or partially hinder its function". The agency said 58 homes of prosecutors and judges have been searched.
Officials also said 2,745 judges and prosecutors have been dismissed.
Another 149 police were detained in Ankara, according to Anadolu, citing the office of the city's governor.