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."
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 the Kurdish minority.
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.
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.
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.
Addressing large crowds after landing at 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 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.