Some 2,839 soldiers, including high-ranking officers, have been arrested after an attempted coup that is now over, says Turkey's PM Binali Yildirim.
The attempted coup was a "black stain on Turkish democracy", he said, with 161 civilians killed and 1,440 wounded.
Those held include two army generals, Turkish media say.
Explosions and firing were heard in key cities on Friday night and thousands heeded a call by President Erdogan to rise up against the coup-plotters.
It is unclear who was behind the coup.
The authorities also said 104 suspected coup-plotters had also been killed.
Some 2,745 Turkish judges have also been dismissed in the wake of the coup, state media say.
They are reported to include a member of the country's top court.
President Recep Tayyip Erdogan has blamed a "parallel structure" — a reference to Fethullah Gulen, a powerful but reclusive US-based Muslim cleric whom he accuses of fomenting unrest.
Mr Gulen has rejected any suggestion of links to what happened, saying he condemned "in the strongest terms, the attempted military coup in Turkey". The Turkish government wants his extradition.
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.
The BBC's Katy Watson in Istanbul says people there are shocked — President Erdogan divides opinion, but a military takeover was not something they saw coming.
Events began on Friday evening as tanks took up positions on two of the bridges over the Bosphorus Strait in Istanbul, blocking traffic. Troops were seen on the streets and low-flying military jets were filmed over Ankara.
Shortly after, an army faction issued a statement 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, then in the south-west resort of Marmaris, made a televised address via his mobile phone, urging people to take to the streets to oppose the uprising.
After flying to Istanbul, Mr Erdogan said: "What is being perpetrated is a treason and a rebellion. They will pay a heavy price."
During the violence, the Turkish parliament and presidential buildings in Ankara were attacked. Gunfire was also heard outside Istanbul police headquarters and tanks were said to be stationed outside Istanbul airport.
Broadcaster CNN Turk was temporarily taken off air after soldiers entered the building and tried to take it over. CNN Turk later tweeted a photo of soldiers being arrested by police.
There were reports of fierce clashes in Taksim Square in central Istanbul, and gunfire and explosions were heard near the square. One of the helicopters being flown by rebels was reportedly shot down by government troops in Ankara.
What is happening now?
Prime Minister Yildirim said the situation was now "completely under control" and the government's commanders were now back in charge.
Earlier, acting military chief of staff Umit Dundar said officers from the air force, the military police and armoured units had mainly been involved in the coup attempt.
Although the chief of staff had been rescued, several military commanders were still being held hostage, he said.
Turkish Foreign Minister Mevlut Cavusoglu said on Twitter that eight soldiers who flew to Greece in a helicopter to seek asylum will be extradited. Greece has not yet formally confirmed the move.
A US government spokesman said the Turkish government has closed its airspace to military aircraft, and as a result operations from Incirlik Air Base against the so-called Islamic State had been halted.
Earlier, some 200 unarmed soldiers left Turkey's military headquarters in Ankara and surrendered to police, according to the state-run Anadolu news agency.
Dramatic images showed dozens of soldiers walking away from their tanks with their hands up on one of Istanbul's Bosphorus bridges.