IT BEGAN in the evening. Military vehicles took over the two bridges over the Bosporus; helicopters clattered and military jets roared overhead. Soon came the news, familiar to an older generation of Turks but forgotten by the current one: soldiers had staged a coup. They declared in a statement: “To restore the constitutional order, human rights and freedoms, the rule of law, and public order, the Turkish armed forces have taken complete control of the country.”

Within a few hours, though, it became clear they were losing their gamble. Amid reports of fighting, explosions at the parliament, anti-coup street protests—and even a report of a loyalist jet shooting down a coup-plotters’ helicopter—it was plain that the soldiers had failed to swiftly establish control. That is a key requirement of a successful coup. Gradually, several current and former army commanders, as well as all of the country’s major political parties, denounced the subversion of democracy. The leaders of the West—led by Barack Obama, Angela Merkel and the European Union's top officials—came down firmly on the side of Turkey’s elected but deeply flawed president, Recep Tayyip Erdogan.

By the morning of July 16th Turkish officials reported that the coup had been thwarted, although a standoff continued on at least one army base. The situation was “90% under control”, the country’s EU minister said. According to the deputy chief of staff, at least 194 people, including 104 “coup-plotters”, had been killed in the fighting. The whereabouts of a number of generals allegedly held hostage by the coup junta remained unknown, he said.

Though seemingly well organised at first, the plotters seemed to represent only a minority faction of military officers. Units that had taken over the airport melted away, their commander saying he did not support the coup. By early morning the main state broadcaster, which had aired the coup leaders’ announcement, was back in the hands of the government. With fighting still taking place in Istanbul, Mr Erdogan made a triumphant return to the city, appearing on television to announce that those responsible for the coup attempt would pay a “heavy price”.

The plotters had struck in classic fashion, while the president was away by the seaside on holiday. At first, the only way Mr Erdogan could get his message out was by linking up with a private TV channel by mobile phone using FaceTime, a video communication app. As the presenter held her telephone’s screen up to the camera, Mr Erdogan condemned what he called an uprising by “a small group within our armed forces”, and urged the people to defy the curfew by turning out into the streets. He accused the Gulen community, a secretive Islamic movement that had been his erstwhile allies but are now mortal enemies, of spearheading the coup. His recently appointed prime minister, Binali Yildirim, warned that security forces loyal to the government would “use force against force.”

Supporters answered their leader’s call, streaming onto public squares in several cities and at Istanbul’s main airport. At mosques across the city, muezzins called for people to protest against the coup. In Istanbul, a group of Erdogan supporters made their way towards the city’s main shopping street, chanting “Allah is Great”. In a less confident sign, dozens of people lined up outside bank machines to withdraw money.

There was bloodshed. Television showed footage of a helicopter gunship firing on groups of people; in another incident people carried away bodies after a crowd that attempted to march on the Bosporus bridge was met with live fire. Explosions rocked the country’s parliament. Turkey’s state-run Anadolu Agency reported that helicopters and fighter jets had struck a police base, killing at least 17 people. Gunshots and explosions could be heard in some areas of Istanbul.

Turkey’s political and social divisions have been growing since 2013, when the country was rocked by anti-government protests and a corruption scandal that cost three cabinet ministers their posts. Mr Erdogan and his supporters have accused the Gulenists of masterminding both the unrest and the bribery scandal.

As the war in Syria spilled over into Turkey, a wave of terrorist attacks over the past year has heightened the sense of a crisis. In the latest of these, three Islamic State jihadists killed 45 people in an attack on Istanbul’s main international airport on June 28th. The long-running war with Kurdish militants has also been rekindled.

Even amid such tensions, few Turks imagined that another coup of the sort that plagued the country since the 1960s might be possible. Mr Erdogan’s AK party, in power since 2002, commands roughly half of the electorate. In the 2000s the army appeared to have been defanged through a series of high-profile trials of senior officers on conspiracy charges, believed to be engineered by the Gulenists with Mr Erdogan’s help. Lately, as he has steered a more nationalist line, Mr Erdogan has started to release the jailed generals and rebuild ties with the army. Perhaps the return of war in the country’s Kurdish south-east gave the army the impression that it could also have back its influence in how the government is run.

Whether or not the attempted coup has failed, it will have severe repercussions for Turkish democracy. If Mr Erdogan survives it, he will emerge stronger and more determined than ever to crack down on domestic opponents. His long-running quest to grant himself even more political power by changing the constitution to create an executive presidency will only be strengthened. If he is overthrown, the coup-makers will face furious resistance not only from Mr Erdogan’s supporters but from those Turks convinced that the only thing worse than Mr Erdogan’s increasingly authoritarian rule is to be ruled by the generals. Further bloodshed may be in store.

Read more:

Turkey’s failed coup gives its president a chance to seize more power

Jul 16th 1230 GMT: This article has been updated to include statements from the Turkish government