While the military factions clearly did not have enough support within the military to finish the job, they also appeared to miscalculate how the plot would be received by those who have long wished to see the end of Mr. Erdogan and his government.

The coup plotters, Mr. Ulgen said, appeared to “grossly misjudge the sentiments of the Turkish people, which over time, despite Turkey’s own democratic shortcomings, have turned very anti-military intervention.”

Under Mr. Erdogan, Turkey has cracked down severely on journalists, sending many to jail and charging others with insulting Mr. Erdogan, a crime in Turkey. But ultimately, in many ways, it was modern media that helped Mr. Erdogan fend off the coup.

As the coup unfolded, he was able to communicate with the country over FaceTime, and it was anti-coup coverage of a number of Turkish outlets that, analysts said, helped sway the tide of public opinion and allow government officials a platform to communicate with the public. Among those outlets was CNN Turk, which has faced the wrath of the government over coverage officials believe to be pro-Kurdish.

The coup plotters seemed stuck in the 1970s, having seized, for a time, the state broadcaster TRT, while other news channels continued coverage, opposing the coup. Turks were able to communicate over social media, sometimes using a VPN when Twitter or Facebook seemed to be inaccessible.

“It’s a total media story,” said Asli Aydintasbas, a Turkish journalist and writer. “This was about not being able to control the message.”

Ms. Aydintasbas was attending a dinner party Friday when guests were alerted to messages on Twitter about the intrigue unfolding.

Someone joked that it might be a coup.

“We all laughed, because it’s not an option in Turkey these days,” she said. “The idea of a coup is so retro.”