Addressing a crowd of thousands of flag-waving supporters at the airport later, Erdogan said the government remained at the helm, although disturbances continued in Ankara.
He also said many commanders were taken to "unknown locations".
Yildirim said the putsch bid had fallen apart as almost 3,000 soldiers suspected in involvement were detained.
It said: "There has been large-scale military action in Turkey, with the military deployed to the streets and widespread reports of gunfire and explosions in Ankara and Istanbul".
Erdogan accused the coup plotters of trying to kill him and launched a purge of the armed forces, which last used force to stage a successful coup more than 30 years ago.
British Foreign Secretary Boris Johnson says he has spoken to his Turkish counterpart, Mevlut Cavusoglu, to underline support for Turkey's "democratic elected government and institutions" after an overnight coup attempt. While Turkey demanded their extradition, Greece said it would hand back the helicopter and consider the men's asylum requests. In Ankara, military aircraft were seen flying low overhead, attacking the National Intelligence Agency's building and police special forces headquarters, according to Daily Sabah.
The coup attempt marks Turkey's first military uprising since 1997, when several influential army generals forced Islamist Prime Minister Necmettin Erbakan to resign.
Prime Minister Binali Yildirim said 161 people have been killed and 1,440 have been injured in the violence that ensued Friday night.
He told BBC Radio 4's Today programme: "Of course Turkey is an important North Atlantic Treaty Organisation ally, where Turkey sits vis-a-vis the fight against Isil's so-called Islamic State is absolutely critical".
"Hamas congratulates the great Turkish people, their elected leadership headed by President Erdogan, and their loyal [political] parties and security forces and military for their victory", the movement said in a statement.
'We will put forward a motion, which will demand the execution of those who have been involved in the coup attempt, ' he wrote on Twitter.
Turkey's presidential administration has warned about the possibility of a new military coup attempt in the country.
Erdogan, who said, "I never believed in a power higher than the people", vowed that the coup plotters will pay a "very heavy price".
Military plotters, calling themselves a "Peace Council", said in a statement read out later on state TV channel TRT that they sought to "reestablish constitutional order, democracy, rights and freedoms", while promising to maintain "good and friendly relations with countries". A Reuters witness in Istanbul, pointing out a pilot, stated all upcoming flights from the Istanbul airport had actually been canceled.
An arm of the Turkish military announces late Friday it is seizing power in Turkey to restore order. People faced off against troops who had blocked key bridges over the Bosporus that link the Asian and European sides of Istanbul.
Secretary-General of the Qatar-based International Union for Muslim Scholars, Ali Mohyi al-Din al-Qaradaghi, for his part, called on the Turkish public to "stand by those who were chosen by the people in democratic elections in the face of those who want to destroy Turkey".
Generals were accustomed to playing a dominant role in the Turkish state, after carrying out four military coups from 1950 to 2000.
Soguel reported from Istanbul.
It follows a period of political turmoil in the country, which critics blamed on Erdogan's increasingly authoritarian rule, which has included a government shake-up, a crackdown on dissidents and opposition media and renewed conflict in the mainly Kurdish areas of the south-east.