Early Saturday morning, Turkey's President Recep Tayyip Erdoğan was on the brink of being overthrown by a section of his military.
On holiday in Marmaris in the southwest, the President had escaped assassination or detention by less than 30 minutes in an attack by commandos. However, he seemed to be cut off. The military controlled the airspace and key positions in Istanbul and the capital Ankara. It was attacking the Parliament building and intelligence headquarters. And it appeared to control the airwaves, having taken over State TV and forced the anchorwoman to read, over and over, the declaration of the coup to restore democracy and human rights.
How to respond, if not through State outlets? Erdoğan answered with an appeal through the Internet and FaceTime on iPhones. He asked the public to take to the streets in protest.
Observers were sceptical, even laughing at a President having to pop up on mobile phone screens to rescue himself. But hours later, with Erdoğan evading the dissident Air Force to make his way to Istanbul's Atatürk Airport and giving an ad hoc press conference, the public display had rallied security forces backing the Government. The coup collapsed.
This was an ironic 21st-century marker for social media and politics, not just in Turkey but far beyond. Having tried to suppress dissent by cutting off new media's channels, Erdoğan had taken advantage of them.
Erdoğan's Government and the judiciary have long blocked social media that they see as provocative and dangerous. From 2007, Turkish courts barred YouTube, initially over "insults" from abroad of the founder of the Turkish Republic, Kemal Atatürk. The ban was lifted in 2010, but briefly re-imposed on several occasions. Twitter and Facebook have also been restricted over material deemed offensive or politically sensitive.
Within an hour of the first reports on Friday night of an uprising, the Turkish Government resorted to its tried and tested methods.
But less than two hours later, the internet monitor Dyn Research reported that Facebook and Twitter were again open.
The reason is not hard to discover. An official, working within the Turkish agencies overseeing new media, confirmed that Turkish ISPs received an e-mail from the Government’s internet authority (TİB) at 1:35 a.m, asking them to “urgently” lift the bans on media channels.
Far from being just a heavy-handed suppressor of media, Erdoğan is a shrewd manipulator. In 2008, even as his Government was banning YouTube, he explained to the public that they could bypass the blocks using alternative servers: "I do access the site. Go ahead and do the same."
Early Saturday, he was making the most of his advice. Within minutes of the e-mail to ISPs, the President was on FaceTime. While State TV was in the hands of the President's opponents, private channels such as CNN Türk eagerly broadcast the appeal, showing it live and in numerous repeats.
Erdoğan's staff then put out a series of tweets, on both his personal and official accounts, for the public to rally.
The State news agency Anadolu, which had not been taken over by the anti-Government forces, and the police authority tweeted similar messages.
As Erdoğan returned to Istanbul, his Twitter accounts maintained the rallying call. They combined threats against those involved in the coup with images of people defending "democracy".
By late Saturday morning, the Presidential account could proclaim Erdoğan's authority as he addressed a crowd at Atatürk Airport: “The President and the government are on duty; let us not leave the streets."
Unsurprisingly, Erdoğan's conditional embrace of media freedom was short-lived. On Saturday, the Internet Authority banned 13 more websites, including six news outlets and two TV channels. Among them is Mediascope.tv, known for its innovation in broadcast of breaking news through the platform Periscope.
Those banned sites join not only a large number of outlets blocked before the coup attempt, but also both "traditional" and "new" media who have been forced to disband or taken over by the State. Turkey is likely to enhance its record as the world's largest jailer, per capita, of journalists amid a purge which has already arrested / suspended more than 50,000 State employees.
But the wonder of 21st-century social media, as shown by Recep Tayyip Erdoğan, is that you can both suppress and embrace it. You can treat it both as a threat and an asset. You can even employ it to proclaim "democracy" in a crackdown and a state of emergency, as quoted on the President’s twitter account: ‘Turkey has a history full of democratic victories and it will always uphold democracy’.