Forces loyal to the Turkish government fought today to crush the remnants of a military coup attempt which crumbled after crowds answered President Tayyip Erdogan's call to take to the streets and dozens of rebels abandoned their tanks.
Turkish Prime Minister Binali Yildirim said 161 were killed in the coup attempt against the government, including many civilians, after a faction of the armed forces tried to seize power using tanks and attack helicopters.
Some strafed the headquarters of Turkish intelligence and Parliament in the capital, Ankara, and others seized a major bridge in Istanbul.
Yildirim, speaking outside his Cankaya palace in Ankara, and flanked by top general Hulusi Akar who was held during the coup attempt, also described the putsch bid as a "black stain" on Turkish democracy. He added that 1,440 people had been wounded.
Erdogan appeared to accuse the coup plotters of trying to kill him and said he would purge the armed forces, which in the past have staged a number of successful coups, even if not for more than 30 years.
"They will pay a heavy price for this," he said. "This uprising is a gift from God to us because this will be a reason to cleanse our army." Later, the presidency warned on Twitter that another uprising could be staged at any time.
Turkish authorities have already detained 2,839 soldiers on suspicion of involvement, officials said. The chief of staff, who had been reported held hostage by the rebels, has been rescued, a senior official said.
A successful overthrow of Erdogan, who has ruled Turkey since 2003, would have marked one of the biggest shifts in the Middle East in years, transforming a major US ally while war rages on its border.
However, a failed coup attempt could still destabilise a NATO member that lies between the European Union and the chaos of Syria, with Islamic State bombers targeting Turkish cities and the government also at war with Kurdish separatists.
Erdogan, who had been holidaying on the southwest coast when the coup was launched, flew into Istanbul before dawn today and was shown on TV outside Ataturk airport.
Addressing a crowd of thousands of flag-waving supporters at the airport later, Erdogan said the government remained at the helm, even though disturbances continued in Ankara.
Erdogan, whose Islamist-rooted ideology lies at odds with supporters of modern Turkey's secular principles, said the plotters had tried to attack him in the resort town of Marmaris.
"They bombed places I had departed right after I was gone," he said. "They probably thought we were still there."
In a live statement broadcast on CNN Turk, Umit Dundar, acting armed forces chief of staff said many military commanders have been taken hostage by the rebels but he declared that Turkey has "closed the chapter" on coups for good.
Erdogan's AK Party, with roots in Islamism, has long had a strained relationship with the military and nationalists. The armed forces have had a history of mounting coups to defend secularism, but have not seized power directly since 1980.
Operations involving police special forces and the military were still underway to regain control of the armed forces headquarters in Ankara, one official said.
In a night that sometimes verged on the bizarre, Erdogan took to social media even though he is an avowed enemy of the technology when his opponents use it, frequently targeting Twitter and Facebook.
Erdogan addressed the nation via a video calling service, appearing on the smartphone of a CNN Turk reporter who held it up to a studio camera so viewers to the network could see him.
Erdogan said the coup attempt had been encouraged by the "parallel structure". This is his shorthand for followers of Fethullah Gulen, a Muslim cleric whom he has repeatedly accused of trying to foment an uprising in the military, media and judiciary.
Gulen, who lives in self-imposed exile in the United States, once supported Erdogan, but became a nemesis. The pro-Gulen Alliance for Shared Values said it condemned any military intervention in domestic politics.
The pro-coup faction said in an emailed statement from the Turkish military general staff's media office address that it was determinedly still fighting.
Gunfire and explosions had rocked both Istanbul and Ankara through the night after soldiers took up positions in both cities and ordered state television to read out a statement declaring they had taken power. However, by dawn the noise of fighting had died down considerably.
About 50 soldiers involved in the coup surrendered on one of the bridges across the Bosphorus Strait in Istanbul after dawn today, abandoning their tanks with their hands raised in the air. Reuters witnesses saw government supporters attack the pro-coup soldiers who had surrendered.
Earlier, around 30 pro-coup soldiers had surrendered their weapons after being surrounded by armed police in Istanbul's central Taksim square.
They were taken away in police vans as a fighter jet repeatedly screeched overhead at low altitude, causing a boom that shook surrounding buildings and shattered windows.
Lawmakers in hiding
The coup began with warplanes and helicopters roaring over Ankara and troops moving in to seal off the bridges over the Bosphorus Strait that links Europe and Asia in Istanbul.
Authorities had shut the strait to tanker traffic, shipping agent GAC said.
In the early hours, lawmakers were hiding in shelters inside the parliament building, which was being fired on by tanks. Smoke rose up from nearby, Reuters witnesses said. An opposition MP told Reuters,the Parliament was hit three times and that people had been wounded.
A senior Turkish official said later today attacks on the Parliament had "largely stopped".
A Turkish military commander also said fighter jets had shot down a helicopter used by the coup plotters over Ankara. State-run Anadolu news agency said 17 police were killed at special forces headquarters there.
Momentum turned against the coup plotters as the night wore on. Crowds defied orders to stay indoors, gathering at major squares in Istanbul and Ankara, waving flags and chanting.
"We have a prime minister, we have a chief of command, we're not going to leave this country to degenerates," shouted one man, as groups of government supporters climbed onto a tank near Ataturk airport.
US secretary of state John Kerry said he phoned the Turkish foreign minister and underlined "absolute support for Turkey's democratically elected, civilian government and democratic institutions".
European Council president Donald Tusk called for a swift return to Turkey's constitutional order, saying tensions there could not be resolved by guns.
Flag carrier Turkish Airways resumed flights today, Erdogan said. Malaysia Airports, the operator of Sabiha Gokcen International airport, Istanbul's second airport, said it would continue to process flights in and out of Turkey.
Soldiers took control of Turkish Radio and Television coperation (TRT) state television, which announced a countrywide curfew and martial law. An announcer read a statement on the orders of the pro-coup faction that accused the government of eroding the democratic and secular rule of law. Turkey would be run by a "peace council" that would ensure the safety of the population, the statement said.
TRT went off the air shortly afterwards. It resumed broadcasting early morning today.
Turkey is one of the main backers of opponents of Syrian President Bashar al-Assad in that country's civil war, host to 2.7 million Syrian refugees and launchpad last year for the biggest influx of migrants to Europe since World War II.
Turkey has suffered numerous bombings and shootings this year, including an attack two weeks ago by Islamists at Ataturk airport that killed more than 40 people, as well as those staged by Kurdish militants.
After serving as prime minister from 2003, Erdogan was elected President in 2014 with plans to alter the constitution to give the previously ceremonial presidency far greater executive powers.
Turkey has enjoyed an economic boom during his time in office and has dramatically expanded its influence across the region. However, opponents say his rule has become increasingly authoritaries.