Turkish Prime Minister Binali Yildirim says 2,839 members of military have been detained in connection with an attempted coup. (Reuters)

Turkish Prime Minister Binali Yildirim says 2,839 members of military have been detained in connection with an attempted coup. (Reuters)

The Turkish government on Saturday quelled most of the last threats from an attempted military coup, but it was a greatly diminished Turkey that emerged from the chaos of the night before.

As dazed citizens stumbled through streets littered with the remains of tanks and armored vehicles used by the renegade troops, authorities embarked on a sweeping roundup of thousands of people suspected of involvement in what appears to have been a long-planned effort to replace Turkey’s democratically elected government with a military junta.

The widespread sense of relief that the attempt had failed was tempered, however, by foreboding. Turkey, until recently hailed as a model of democracy in the Muslim world, must now confront the reality that this NATO member remains vulnerable to the kind of domestic and military upheaval that once earned the country a reputation as a chronically unstable state.

There were also concerns that the unfolding crackdown on participants in the coup attempt will provide further justification for the creeping authoritarianism of President Recep Tayyip Erdogan, who had already been targeting opponents of his government. Analysts expressed concern that opposition to Erdogan would be depicted as equal to coup plotting.

“People here are celebrating, but what they don’t understand is that they are part of a trap that Erdogan is setting for them. He’s going to use them for his own power,” said Ozgur Guleray, 30, a chef at a restaurant in downtown Istanbul who watched as thousands of revelers gathered in Taksim Square on Saturday evening to celebrate the government’s suppression of the coup attempt.

1 of 63 Full Screen Autoplay Close Skip Ad × The scene in Turkey after an attempted coup View Photos Turkey’s military tried to overthrow the government of President Recep Tayyip Erdogan. Caption The nation’s military tried to overthrow the government of President Recep Tayyip Erdogan. July 17, 2016 Women mourn near the flag-draped coffin of a relative in Istanbul, during the funeral of seven victims of the July 15 coup attempt. Aris Messinis/AFP/Getty Images Buy Photo Wait 1 second to continue.

The extensive violence deployed by those who sought to overthrow Erdogan suggested the plot did not represent a bid to assert democratic principles, despite a declaration to that effect made by the elements of the military who briefly seized control of some of the state institutions, including the national broadcaster.

At least 265 people were killed late Friday and early Saturday as tanks commandeered bridges and highways. Renegade warplanes dropped bombs on protesters and on the nation’s parliament and other government facilities, turning parts of Istanbul and the capital, Ankara, into war zones. The dead included 104 alleged coup participants and 161 civilians.

The coup was thwarted in part by the masses of people who swarmed into the streets in response to an appeal by Erdogan, issued over a TV anchor’s iPhone, to come to the help of the embattled government. There were widespread reports on Saturday of bloody revenge killings against rebel soldiers.

[On the streets of Istanbul, anger, joy, devastation and celebration]

A triumphant and combative Erdogan, addressing a huge crowd gathered in Istanbul Saturday evening, hailed the popular outpouring of support and vowed a tough response to the coup plotters.

“By confronting them and chasing them, we will overcome them,” he told the cheering supporters.

He reiterated his accusation that a U.S.-based cleric, Fethullah Gulen, who lives in Pennsylvania, was behind the plot, and called for his extradition by the United States. “Once they hand over that head terrorist in Pennsylvania to us, everything will be clear,” Erdogan told the crowd.

Rogue officers of Turkey’s military declared martial law and attempted to overthrow the government of President Recep Tayyip Erdogan overnight, but Erdogan a few hours later said his government is in control. (Jason Aldag/The Washington Post)

Secretary of State John F. Kerry, during a stop in Luxembourg, said the United States would support investigations to determine who instigated the coup attempt, but he did not immediately say whether Gulen would be extradited.

Kerry also criticized the coup attempt, saying that elections are the proper way to settle disputes in a democracy.

“I must say,” he added, “it does not appear to have been a very brilliantly planned or executed event. But let’s reserve judgment until all the facts are in.”

The Gulenist movement in Turkey denied involvement and condemned the coup effort.

Erdogan and other government officials stressed that the plot involved a “minority” of fringe Gulenist supporters, and the response on the streets indicated that those involved had no popular support.

[Fethullah Gulen: The Islamic scholar Turkey blames for the failed coup]

Nonetheless, details of the coup plot that emerged Saturday suggested the existence of a serious threat to Turkey’s cohesion from within the ranks of its powerful military, NATO’s second-largest army and a major U.S. partner in the war against the Islamic State.

Among those detained were Gen. Erdal Ozturk, commander of the Third Army, Turkey’s largest field army, and Gen. Adem Huduti, the commander of the Second Army, which controls the country’s borders, as well as a rear admiral who had until recently commanded the coast guard, and multiple colonels in charge of mechanized brigades and other key army units.

The alleged mastermind was Gen. Akin Ozturk, who commanded the Turkish air force until last summer and was a member of the Supreme Military Council. He also has been detained and will be charged with treason, officials said.

The air force appears to have been deeply involved, with pilots commandeering F-16 fighter jets and helicopters and seizing control of at least one military air base, Ackinci, outside Ankara.

Some personnel at Incirlik, a major NATO air base that is home to the largest stockpile of nuclear weapons in Europe and about 1,000 U.S. troops, are also suspected of taking part in the attempted government overthrow, a senior Turkish official said.

“We suspect that Incirlik was used to refuel hijacked aircraft last night,” he said, speaking on the condition of anonymity because of the sensitivity of the subject. It appears, he added, that “a small group of Turkish troops stationed at Incirlik supported the coup attempt.”

U.S. officials said the United States had boosted force protection levels on bases in Turkey to their highest level, and the U.S. Embassy in Ankara warned Americans to stay away from Incirlik, outside the southern city of Adana.

U.S. bombing runs over Iraq and Syria remained suspended because much of Turkish military airspace remains closed, and the U.S. government has adjusted its flight roster to sustain the anti-Islamic State war effort, said Pentagon press secretary Peter Cook. Power was cut to the base, but U.S. operations there run on “internal power sources,” he added.

[U.S. military boosts security in Turkey to highest level during coup attempt]

Though the coup attempt failed, the effort will be a tremendous blow to the prestige of Turkey’s military, and more broadly Turkey’s standing as a regional power, said Soner Cagaptay of the Washington Institute for Near East Policy.

The United States’ reliance on Incirlik for the war against the Islamic State must now be in question, he said, and the trustworthiness of Turkey’s military, at home and abroad, will be in doubt.

“The military was considered the most trusted institution in the country,” he said. “The Turkish military will experience a freefall in its standing.”

Some of those involved in the coup attempt appear to have fled as the plot fell apart. On Saturday, Greece announced that a Turkish military helicopter made an emergency landing at Alexandroupoli’s airport. Greece detained eight men aboard, who requested political asylum. Turkey has requested their extradition.

Turkish authorities also detained 2,475 judges and other members of the judiciary who were suspected of supporting what appeared to have been a far-reaching operation. Evidence seized by investigators suggests that the coup plotters had drawn up extensive lists of people who were to be installed as governors, administrators and heads of government agencies in the event that the operation succeeded, according to the senior Turkish official.

The government is still not sure it has rounded up all the coup participants, and there are fears that “rogue” aircraft may still be on the loose, he said.

[An old-school coup fails to topple Turkey’s powerful president]

Nonetheless, in Istanbul, a semblance of normality returned. By early afternoon, the bridges across the Bosporus were reopened and traffic began to move again after a night of gunfire, explosions and violent confrontations.

Small groups of residents gathered on corners and debated in hushed tones, and shelves in many local shops were completely empty after a late-night rush to stock up on food and water.

The U.S. Embassy had warned citizens against heading to the airport amid reports of ongoing sporadic gunfire, but later in the day, commercial flights appeared to be returning to normal. The U.S. Federal Aviation Administration said it had barred American commercial aircraft from flying into or out of Turkey.

Sly reported from Irbil, Iraq. Karatas reported from Istanbul. Hugh Naylor in Istanbul, Ishaan Tharoor, Ashley Halsey and Dan Lamothe in Washington, Carol Morello in Luxembourg, Menekse Tokyay in Ankara and Thomas Gibbons-Neff in Frankfurt, Germany, contributed to this report.

Read more:

Turkey’s cat-and-mouse game with the Islamic State

Turkey’s most-read newspaper begins publishing pro-Erdogan articles after government seizure

Today’s coverage from Post correspondents around the world