Some 2,839 soldiers, including high-ranking officers, have been arrested over an attempted coup that is now over, says Turkey’s PM Binali Yildirim.
In a night he called a “black stain on Turkish democracy”, he said 161 people had been killed and 1,440 wounded.
Explosions and gunfire were heard in Ankara, Istanbul and elsewhere overnight and thousands of Turks heeded President Erdogan’s call to rise up against the coup-plotters.
It is not clear who is behind the coup.
President Recep Tayyip Erdogan blamed a “parallel structure”, in a clear reference to Fethullah Gulen, a powerful but reclusive US-based Muslim cleric he accuses of fomenting unrest.
However, in a statement, Mr Gulen rejected any suggestion he had links to the events, saying he condemned “in the strongest terms, the attempted military coup in Turkey”.
Soldiers with their hands up on Istanbul’s Bosporus Bridge
Image caption
The surrender of soldiers in Istanbul was captured live on television
Read the latest live updates
International reaction
In pictures: Turkey coup attempt
Why did Turkish coup plot fail?
Reasons behind coup: By BBC’s Middle East Editor Jeremy Bowen
The attempted coup happened because Turkey is deeply divided over President Erdogan’s project to transform the country and because of the contagion of violence from the war in Syria.
President Erdogan and his AK Party have become experts at winning elections, but there have always been doubts about his long-term commitment to democracy. He is a political Islamist who has rejected modern Turkey’s secular heritage. Mr Erdogan has become increasingly authoritarian and is trying to turn himself into a strong executive president.
From the beginning Mr Erdogan’s government has been deeply involved in the war in Syria, backing Islamist opposition to President Assad. But violence has spread across the border, helping to reignite the fight with the Kurdish PKK, and making Turkey a target for the jihadists who call themselves Islamic State.
That has caused a lot of disquiet. Turkey has faced increasing turmoil and the attempt to overthrow President Erdogan will not be the last of it.
Jump media playerMedia player helpOut of media player. Press enter to return or tab to continue.
Media caption”Here in Turkey there is confusion”, reports the BBC’s Katy Watson
Events began on Friday evening when tanks took up positions on two bridges over the Bosphorus Strait in Istanbul, blocking it to traffic. Troops were seen on the streets and low-flying military jets were filmed over Ankara.
Shortly after, a faction of the army released a statement saying that a “peace council” was running the country, and it had launched the coup “to ensure and restore constitutional order, democracy, human rights and freedoms”.
President Erdogan was in the south-west holiday resort of Marmaris at the time. He made a televised address, via his mobile phone, urging people to take to the streets to oppose the uprising.
He then flew on to Istanbul, saying Marmaris had been bombed after he left.
In a speech at Istanbul airport, Mr Erdogan said: “What is being perpetrated is a treason and a rebellion. They will pay a heavy price.”