Turkish President Recep Tayyip Erdogan has flown in to Istanbul, after an army group said it took over the country.
He was seen surrounded by cheering supporters, saying in a live TV speech that the coup attempt was an “act of treason” and the army must be cleansed.
Sixty people died during overnight clashes, many of them civilians, and 754 soldiers were arrested, officials said.
Prime Minister Binali Yildirim said the situation was largely under control.
He has ordered the military to shoot down aircraft being used by coup plotters.
Earlier, one of the helicopters being flown by forces involved in the coup attempt was shot down over the capital Ankara.
Meanwhile, the whereabouts of the military chief of staff, Gen Hulusi Akar, are still unknown. He is reported to have been taken hostage by rebel soldiers.
Gen Umit Dundar, commander of the 1st Army, has been appointed acting chief of staff.
Sporadic gunfire is still reported in major cities.
Reports also say rebel soldiers in some areas have been surrendering their weapons to police loyal to Mr Erdogan.
The surrender of one unit of 60 soldiers, who had taken control of one of the Bosphorus bridges in Istanbul, was shown live on TV on Saturday morning.
Istanbul’s main Ataturk airport is now under army control, and flights – which had been interrupted for some hours – were due to resume from 06:00 (03:00 GMT).
In a statement, the Turkish foreign ministry said the coup attempt “was foiled by the Turkish people in unity and solidarity. Our president and government are in charge”.
“Turkish Armed Forces was not involved in the coup attempt in its entirety. It was conducted by a clique within the armed forces and received a well-deserved response from our nation.”
It is unclear who is leading the coup faction or how much support it enjoys.
The group earlier declared that a “peace council” now ran the country and there was a curfew and martial law.
Soldiers were seen at strategic points in Istanbul, with jets flying low in Ankara.
Two large explosion were also heard near Istanbul’s central Taksim Square.
There were also reports of blasts at parliament building in Ankara. MPs were believed to be hiding in shelters.
Broadcaster CNN Turk was reportedly taken over by soldiers, and its live broadcast was cut.
In Washington, US President Barack Obama urged all parties in Turkey to support the “democratically elected government”.
Nato called for “full respect” for Turkey’s democratic institutions.
European Council President Donald Tusk said the country was “a key partner for the European Union”.
“We call for a swift return to Turkey’s constitutional order,” he added.
Speaking in Istanbul in the early hours on Saturday, President Erdogan promised to clean up the army.
“Those who drive around in tanks will have to go back to where they came from,” he said.
He also dismissed the coup leaders as “terrorists”.
Mr Erdogan earlier told CNN Turk by mobile phone the action was by a “parallel structure” that would bring the necessary response. He has used this term in the past to refer to Fethullah Gulen, a US-based Muslim cleric he accuses of fomenting unrest.
However, in a statement, Mr Gulen rejected any suggestion he had links to the events.
“I condemn, in the strongest terms, the attempted military coup in Turkey,” he said.
Mr Erdogan had called on people to take to the streets to oppose the uprising.
He said: “I urge the Turkish people to convene at public squares and airports. I never believed in a power higher than the power of the people.”
The president said he had returned to Istanbul from the holiday resort of Marmaris in the south-west of the country. He said the town was later bombed.
Defying the announced curfew, a number of Erdogan supporters turned out on Taksim Square in Istanbul late on Friday.
There were reports of clashes there, with some on Twitter saying that gunfire had been heard near the square.
After the military takeover was announced, a statement from the group was read out on national broadcaster TRT. It said that the democratic and secular rule of law had been eroded by the current government. There would be new constitution, it said.
Mr Yildirim told NTV by telephone: “There was an illegal act by a group within the military that was acting out of the chain of military command. Our people should know that we will not allow any activity that would harm democracy.”
Traffic was stopped from crossing both the Bosphorus and Fatih Sultan Mehmet bridges in Istanbul.
Gunfire was also heard outside Istanbul police HQ and tanks were said to be stationed outside Istanbul airport.