
ISTANBUL — As dawn broke over Turkey on Saturday, the country’s citizens emerged sleep-deprived and angst-ridden after a night of violence that left hundreds of people dead and felt more like life in war-stricken neighbors like Syria or Iraq.
Thousands of soldiers and officers were purged from the military as the government of President Recep Tayyip Erdogan sought to assert control after an attempted coup, also targeting perceived enemies of the state in the judiciary.
By the afternoon, after a standoff in Ankara, the capital, the government had wrested back an army headquarters building held by coup plotters.
Erdogan, who had frequently talked of conspiracies afoot to undermine his power, was back in control, seemingly as powerful as ever, and perhaps even more paranoid.
The drama had a deep resonance for Western policy makers, who have long looked upon Turkey as a crucial partner in the fight against terrorism and an anchor of stability in a region full of trouble.
The United States has sought close cooperation with Turkey in the fight against the Islamic State, while Europe has relied on the country to help stem the flow of refugees from war-torn countries of the Middle East to the Continent.
“The whole night felt like doomsday,’’ said Sibel Samli, an independent film producer in Istanbul. “People flocked to the markets to get bread, eggs, and water. People were going to cash machines to draw out cash.’’
The night before, a steamy Friday, was just getting going when the first hint came that something was not right: News broke that the military had sealed off two bridges across the Bosporus.
Fighter jets and helicopters began flying low over Istanbul and Ankara, rattling residents enjoying a night on the town, and sporadic gunshots rang out. Suddenly Turks were transfixed by their cellphones or the televisions in bars and restaurants, trying to figure out what was going on.
No one seemed to know where the president was.
As rumors swirled that the military was maneuvering to thwart a terror plot, or that a hijacked airliner was in the sky, almost from the beginning Turks — given their nation’s history of military meddling in politics — began to wonder if a coup was afoot.
Soon enough, they had their answer: The prime minister, Binali Yildirim, spoke on television and said a renegade faction within the military was attempting to overthrow the government.
A military group, later calling itself the Peace at Home Council — a reference to a mantra of Turkey’s secular founder, Mustafa Kemal Ataturk — issued a statement saying it had seized control of the country.
And so began a surreal evening that stretched until daybreak, punctuated by violence that killed more than 260 people, most of them members of the security forces, as various factions fought one another for control of the country. More than 2,800 members of the military were arrested.
The night seemed to encapsulate the many dramas and conflicts that have roiled Turkey in recent years, from street protests to the bitter fight between Erdogan, an Islamist, and a onetime ally, Muslim cleric Fethullah Gulen, whom the president blamed for the coup attempt, to rising political violence and terrorism.
Samli, the filmmaker, had been sitting with friends at a rooftop bar of a chic hotel on the European side of Istanbul, when a helicopter passed low over their heads.
“We didn’t think anything of it at first because we knew the city was on high terror alerts following recent attacks,’’ she said. “Then we started getting the calls and WhatsApp notifications about the start of a military coup. People were calling one another telling them go home.’’
The first signs that the coup might not succeed came as it become clear that the military failed to secure important government buildings, or to seize elected officials, normally the first actions of a putsch.
Later it was learned that the conspirators had sought out Erdogan at the seaside town of Marmaris, where he was apparently vacationing, but were too late. And then Erdogan himself appeared, from an undisclosed location, and spoke to the nation on the FaceTime app from his cellphone, which was shown on television.
That stunning scene, an embarrassment for a leader who presents himself as all-powerful, seemed to suggest the end. But it was actually the turning point, as he exhorted his followers to take to the streets and gather at the airport in Istanbul, which had been shut by the military, to resist the coup.
Once again — as he did when he faced down a street revolt in 2013 and to win elections, for himself as president and in Parliament for his Islamist Justice and Development Party, or AKP — Erdogan relied on his power base of Turkey’s religious conservatives.
Mosque preachers joined Erdogan’s call to resist. “We will not let Turkey fall!’’ men shouted in the conservative Istanbul neighborhood of Istinye on Saturday morning, firing guns into the air. “God is greatest!’’
The scariest hour was the one just before Erdogan’s jet landed in Istanbul after 3 a.m. Fighter jets flew low over Istanbul, setting off sonic booms that felt like airstrikes. Gunfire crackled throughout the city and in Ankara, where soldiers seized civilian cars to use as barricades.
Several explosions were reported at Parliament, and a helicopter used by the plotters was blown from the sky, officials said. A helicopter landed at the offices of CNN Turk, and soldiers, apparently coup plotters, tried to seize the station during a live broadcast.
“Around 3 a.m. we heard loud fighter jets and explosions,’’ Samli said. “That’s when I felt scared. And this morning everyone is in shock.’’
Late in the night, the sounds of war intermixed with muezzins at mosques exhorting people to go into the streets, and people chanting “Allahu akbar,’’ or “God is greatest.’’
When Erdogan landed in Istanbul in the early-morning hours, chaos was still gripping Istanbul and Ankara, with more explosions and gunshots, but his very appearance seemed to signify that the conspiracy was reaching its end.
In characteristic fashion, as he has when confronted with street protests and a corruption investigation, he vowed to root out the conspirators.
It was becoming clear, by the time Erdogan landed in Istanbul, that those behind the coup did not have enough support within the military, even as the whole episode exposed deep divisions within the military that had not been so apparent.
While the Turkish military has a history of intervening in politics — it carried out three coups in the past five decades — Erdogan and his allies had systematically sought to make the army coup-proof through a series of sensational trials, and it was thought to be incapable of mounting a takeover of the government.
Officials said the main plotters were from the gendarmerie, a military-style police force, the air force, and some elements of the land forces.
Several generals and colonels were arrested — none high-level figures recognizable to the public — and thousands of other rank-and-file officers and soldiers were rounded up Saturday in a purge that is likely to go one for some time.