Under the leadership of Turkish President Recep Tayyip Erdogan, Turkey has become one of the most repressive states when it comes to internet freedom — ranked by Freedom House as the 20th most repressive country in the world, right between Egypt (19) and Venezuela (21).

Erdogan’s government has on occasion imposed complete bans on social media services such as Facebook, Twitter and YouTube, and he has personally filed charges against dozens of Turkish citizens for insulting him online. In a 2014 meeting with an internet freedom group, he reportedly said that he was “increasingly against the internet every day.”

So it is more than a bit ironic that the internet played such a central role in saving Erdogan’s presidency.

While the facts are still coming in, it is obvious the coup’s plotters made some mistakes, most notably by failing in their attempt to capture Erdogan at the seaside resort where he was vacationing Friday night. But they got other things right — at least according to the traditional playbook. Tanks blocked the bridges, troops assaulted the parliament and the airport, the chief of the armed forces was detained, and the plotters grabbed control of key communications media, including state broadcaster TRT and cable channel CNN Turkey.

Apparently, though, they forgot about the internet. Soon after the coup began, internet censorship monitors reported that traffic on Facebook, Twitter and YouTube was being blocked. And while it’s not entirely clear who was responsible — the coup plotters or the government — what is clear is that after about two hours the blocks were removed, and Turkish government officials initiated a full-scale social media campaign to call Erdogan supporters into the streets.

The campaign reportedly included a direct text message from Erdogan to every mobile phone in the country. In what may have been the turning point of the entire affair, Erdogan was able to use his iPhone to broadcast a message to the Turkish people on Facetime, demonstrating that he was still alive and fighting back.

By all accounts, the government’s online communications campaign turned the tide, bringing tens of thousands of people into the streets to confront the army and sparking scenes superficially reminiscent of Tiananmen Square.

The Turkish coup is, of course, not the first time the internet has played an important role in a high-profile political struggle. Russia is generally credited with conducting one of the first modern acts of information warfare in 2007 when it executed denial of service attacks against Estonian media outlets in a dispute over Russian war memorials, and the role of social media in sparking protests following the Russian parliamentary elections in December 2011 led Vladimir Putin to impose one of the most oppressive online censorship regimes in the world.

Many credit social media for enabling the protests that led to the Arab Spring.

However, the Erdogan government’s offensive use of social media may be the first time it has played a determinative role in saving a government from overthrow.

What’s the takeaway? In a recent report for the American Enterprise Institute, my co-authors and I pointed out that the internet is increasingly becoming a mechanism of control, both in the literal sense — it runs our financial system, communications networks and electricity grids — and the political one.

Authoritarian states like China, Iran and Russia have gone from simply censoring the web to using it to spread state propaganda both internally and externally. For example, one recent study found that the Chinese government cranks out nearly 500 million propaganda posts on social media every year, and Russia’s use of “troll houses” to post deceptive material on western news sites has become a source of east-west tension.

What last weekend shows is that the internet has now come of age as a means of directly exercising political power. By his call to action to millions of ardent supporters, President Erdogan was able, in a matter of minutes, to put an army into the streets of key Turkish cities, saving his government and quite possibly himself.

It’s a lesson that should not be lost on anyone.