ANKARA, Turkey (AP) -- Forces loyal to Turkey's president quashed a coup attempt in a night of explosions, air battles and gunfire that left dozens dead Saturday. Authorities arrested thousands of people as President Recep Tayyip Erdogan vowed those responsible ``will pay a heavy price for their treason.''
Turkish police arrest Turkish soldiers at the Taksim Square after a failed coup attempt, in Istanbul, Turkey, on Saturday. (EPA-Yonhap)
The chaos capped a period of political turmoil in Turkey - a NATO member and key Western ally in the fight against the Islamic State group - that critics blame on Erdogan's increasingly authoritarian rule. He has shaken up the government, cracked down on dissidents, restricted the news media and renewed conflict with Kurdish rebels.
Pressure has also come from millions of refugees who have fled violence in neighboring Syria and Iraq, and a series of bloody attacks blamed on the Islamic State group and Kurdish rebels.
Erdogan was on a seaside vacation when tanks rolled into the streets of Ankara and Istanbul. He flew home early Saturday and declared the coup to have failed.
Turkish police officer (R) embrace a man on a tank after the military position was taken over at the Anatolian side at Uskudar in Istanbul on Saturday. (AFP-Yonhap)
The uprising appears not to have been backed by the most senior ranks of the military, and Turkey's main opposition parties quickly condemned the attempted overthrow of the government. Gen. Umit Dundar, newly appointed as acting chief of the general staff, said the plotters were mainly officers from the Air Force, the military police and the armored units.
Prime Minister Benali Yildirim said 161 people were killed and 1,440 wounded in the overnight violence. He said 2,839 plotters were detained. A source at the office of the presidency, speaking on condition of anonymity in line with government rules, said the 161 toll ``excludes assailants.''
Yildirim described the night as ``a black mark on Turkish democracy'' and said the perpetrators ``will receive every punishment they deserve.''
Turkey's NATO allies lined up to condemn the coup. U.S. President Barack Obama urged all sides to support Turkey's democratically elected government. NATO Secretary-General Jens Stoltenberg said he spoke to Turkish Foreign Minister Mevlut Cavusoglu and called for respect for democracy.
The coup attempt began late Friday, with a military statement saying forces had seized control ``to reinstall the constitutional order, democracy, human rights and freedoms, to ensure that the rule of law once again reigns in the country, for law and order to be reinstated.''
Fighter jets buzzed overhead, gunfire erupted outside military headquarters and vehicles blocked two major bridges in Istanbul. Soldiers backed by tanks blocked entry to Istanbul's airport for a couple of hours before being overtaken by pro-government crowds carrying Turkish flags, according to footage broadcast by the Dogan news agency.
The military did not appear unified, as top commanders went on television to condemn the action and order troops back to their barracks.
Erdogan, appearing on television over a mobile phone, had urged supporters into the streets to defend the government, and large crowds heeded his call.
People faced off with troops that had blocked the bridges over the Bosporus, linking the Asian and European sides of Istanbul.
By early Saturday, the putsch appeared to have fizzled, as police, soldiers and civilians loyal to the government confronted coup plotters.
In images broadcast on CNN-Turk, dozens of soldiers walked among tanks with their hands held up, surrendering to government forces. Discarded gear was strewn on the ground. Some flag-waving people climbed onto the tanks.
Colonels and generals implicated in the rebellion were fired and loyal troops rescued the military chief who had been taken hostage at an air base on the outskirts of Ankara, the capital.
Elsewhere, a Blackhawk military helicopter transporting seven Turkish military personnel and one civilian landed in the Greek city of Alexandroupolis, where the passengers requested asylum, according to Greece's defense ministry. Turkey demanded their extradition.
Addressing large crowds after landing at Istanbul's Ataturk Airport, Erdogan said of the plotters: ``They have pointed the people's guns against the people. The president, whom 52 percent of the people brought to power, is in charge. This government brought to power by the people is in charge.''
Fighting continued into the early morning, with the sounds of huge blasts echoing across Istanbul and Ankara, including at least one bomb that hit the parliament complex. Television footage showed broken glass and other debris strewn across a lobby leading to the assembly hall.
CNN-Turk said two bombs hit near the presidential palace, killing five people and wounding a number of others.
Turkey's Prime Minister Binali Yildirim, center, Chief of Staff Gen. Hulusi Akar, center left, Justice Minister Bekir Bozdag, left, Interior Minister Efkan Ala, second right, and Defense Minister Fikri Isik attend a press conference in Ankara, Turkey, Saturday. (AP-Yonhap)
Turkey is a key partner in U.S.-led efforts to defeat the Islamic State group, and has allowed American jets to use its Incirlik air base to fly missions against the extremists in nearby Syria and Iraq. A coup against the democratically elected government could have made it difficult for the United States to continue to cooperate with Turkey.
Erdogan's Islamist government has also been accused of playing an ambiguous role in Syria. Turkey's renewed offensive against Kurdish militants _ who seek more autonomy and are implacable foes of IS _ has complicated the fight against the Islamic State group.
Government officials blamed the coup attempt on a U.S.-based Islamist cleric, Fethullah Gulen. Erdogan has long accused the cleric and his supporters of attempting to overthrow the government. Gulen lives in exile in Pennsylvania and promotes a philosophy that blends a mystical form of Islam with staunch advocacy of democracy, education, science and interfaith dialogue.
Fadi Hakura, a Turkey expert at the Chatham House think tank in London, said it was not clear who was behind the attempted coup, but it appeared to have been ``carried out by lower-ranking officers _ at the level of colonel.''
``Their main gripe seems to have been President Erdogan's attempt to transform his office into a powerful and centralized executive presidency,'' Hakura said.
``I think in the short term this failed coup plot will strengthen President Erdogan, particularly in his drive to turn his office into a strong and centralized executive presidency,'' Hakura added.
Turkey's military staged three coups between 1960 and 1980 and pressured Prime Minister Necmettin Erbakan, a pious Muslim mentor of Erdogan, out of power in 1997.
There have long been tensions between the military _ which saw itself as the protector of the secular Turkish state _ and Erdogan's Islamic-influenced AKP party. Erdogan's government has taken steps, including dismissals and prosecutions of high-ranking active and former officers for alleged coup plots, to bring the military to heel.