Turkey coup: How mobiles beat tanks and saved Erdogan
Hours after the attempted coup began, Turkey's defiant president appealed to supporters to take to the streets and confront the rebels.
But when President Recep Tayyip Erdogan addressed the nation as events unfolded on Friday, he did not do it from the back of a tank, but from a smartphone held up to the camera of broadcaster CNN Turk.
It was an extraordinary moment on an extraordinary night, but one that tells us much about why Mr Erdogan is still in power, and why thousands of soldiers are now in jail.
The coup failed for a number of reasons. Chiefly, the organisers lacked broader military backing and failed to gain public and political support.
But another explanation may lie in the very different ideas the two sides had about how to get their message across.
Late on Friday evening, the scheme seemed well-planned, with rebel troops sealing off Istanbul's bridges over the Bosphorus, surrounding the city's Ataturk airport and stationing tanks outside the presidential palace in Ankara.
But while they also raided major news organisations, the rebels failed to control the narrative and fundamentally misunderstood the significance of social media.
A statement from the group, read on state broadcaster TRT by a journalist reportedly being held at gunpoint, announced that a "Peace at Home Council" was running the country and a curfew and martial law would be declared.
More on Turkey's failed coup:
What you need to know: A brief explainer of a complex story
"What's happening to our country?": Shock in Taksim Square, Istanbul
Who was behind the plot?: The thorny relationship between Turkey's government and military
Turkey's ruthless president: Recep Tayyip Erdogan in profile
Troops also stormed CNN Turk during the night, its Facebook live feed left showing an empty desk and chair.
"We are broadcasting until the last minute, as we think it is important for Turkish democracy and the future of the country," said CNN Turk anchor Basak Sengul, before being ushered out of the studio.
It was Mr Erdogan's message, however, that proved most important and which, combined with similar statements from other senior Turkish politicians, showed the country's democratic leadership was safe and well.
By the time he flew back to Istanbul from the Marmaris holiday resort in southern Turkey, thousands had defied the curfew, some lying down in front of tanks to halt their movement.
Even if those behind the coup had been able to control traditional media, they could not stop people accessing news on Twitter, Facebook, WhatsApp and other platforms.
Monitoring site Turkey Blocks said key sites including Facebook and Youtube had been blocked as the uprising began, later adding that they had seen a two-hour period of social media "throttling" but no evidence of a full internet blackout. Twitter has backed up this assessment.
While such sites have been blocked in previous crises, it is possible the government wanted to keep them up as this worked to their advantage.
What is more, Turkey has a vibrant social media community, and one that knows how to circumvent any restrictions.
Those behind the coup never appeared in full command of the situation, and that was amplified online.
Mr Erdogan even sent a nationwide text out asking people to stand up for democracy, a trick lost on the faction responsible.
If the plotters had owned a textbook on overthrowing a government, it was out of date and from a pre-internet era. What they needed was something for the 21st Century.
For some observers, the big irony of the night was that a tool that has come under attack from Mr Erdogan's government helped save him.
Mr Erdogan once vowed to "wipe out" Twitter, after the platform helped mobilise mass protests in 2013. Yet as Friday's events developed he used it to send a string of tweets rallying his supporters.
Zeynep Tufekci, of the University of North Carolina but who was in Turkey during the coup, tweeted this during the night: "Never thought I'd write: Erdogan takes to Twitter & FaceTime as a coup attempt in Turkey is thwarted by gov't supporters using social media."