One hundred and sixty-one people were killed, including many civilians, after a faction of the armed forces tried to seize power using tanks and attack helicopters. Some strafed the headquarters of Turkish intelligence and parliament in the capital, Ankara, and others seized a major bridge in 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.
“They will pay a heavy price for this,” said Erdogan, who also saw off mass public protests against his rule three years ago. “This uprising is a gift from God to us because this will be a reason to cleanse our army.”
A Turkish broadcaster reported that a purge of the judiciary was also underway.
One government minister said some military commanders were still being held hostage by the plotters. But the government declared the situation fully under control, saying 2,839 people had been rounded up from foot soldiers to senior officers, including those who had formed “the backbone” of the rebellion.
A successful overthrow of Erdogan, who has ruled the country of about 80 million people since 2003, would have marked another seismic shift in the Middle East, five years after the Arab uprisings erupted and plunged Turkey’s southern neighbor Syria into civil war.
However, a failed coup attempt could still destabilize a NATO member and major U.S. ally that lies between the European Union and the chaos of Syria, with Islamic State bombers targeting Turkish cities and the government also at war with Kurdish separatists.
Erdogan, who had been holidaying on the southwest coast when the coup was launched, flew into Istanbul before dawn on Saturday and was shown on television outside Ataturk Airport.
Addressing thousands of flag-waving supporters at the airport later, he said the government remained at the helm, although disturbances continued in Ankara.
Erdogan, a polarizing figure whose Islamist-rooted ideology lies at odds with supporters of modern Turkey’s secular principles, said the plotters had tried to attack him in the resort town of Marmaris.
“They bombed places I had departed right after I was gone,” he said. “They probably thought we were still there.”
Erdogan’s AK Party has long had strained relations with the military, which has a history of mounting coups to defend secularism although it has not seized power directly since 1980.
His conservative religious vision for Turkey’s future has also alienated many ordinary citizens who accuse him of authoritarianism. Police used heavy force in 2013 to suppress mass protest demanding more freedom.
However, he also commands the admiration and loyalty of millions of Turks, particularly for restoring order to an economy once beset by regular crises. Living standards have risen steadily under his rule, and while the economy has hit serious problems in recent years, it grew a greater-than-expected 4.8 percent year-on-year in the first quarter.
Still, the violence is likely to hit a tourism industry already suffering from the bombings, and business confidence is also vulnerable.