For several hours on Friday night hundreds of Turkish soldiers appeared to have taken control of key areas of the main cities of Ankara and Istanbul.
There was little sign of President Recep Erdogan as the plotters took over buildings and media outlets. They needed to secure the support of the public and especially the majority of the military.
Prime Minister Binali Yildirim appeared to be leading resistance to the coup, but as most Turks know, it is President Erdogan who wields the power and has designs on extending it.
If the coup was going to succeed, the conspirators had to keep him out of the picture and they were unable to do so. "I am the chief commander," he said later.
When the tide turned
For hours it was unclear where President Erdogan was. Reports said he was on holiday at the Aegean resort of Marmaris, deep in Turkey's south-west.
The tide turned when the president flew into Istanbul's Ataturk airport and gave a defiant news conference.
The moment he touched base in Istanbul it was clear the government was regaining control and had the support of senior military figures.
Ankara, where his palace and the government are based, was not yet secure, but in Istanbul he was able to address Turkey directly.
It had been "an act of treason and rebellion", he told reporters. Ilnur Cevik, a senior presidential adviser, told the BBC soon afterwards that the coup had been defeated by the will of the Turkish population.
"It's very clear there was a coup attempt but rapidly the situation turned in favour of the government and Erdogan asked the people to flock into the streets in Ankara and Istanbul and that's what they did."
It was the Turkish people who reclaimed Ataturk airport from the military and the people who took back state TV and radio from the military, he said.
Controlling the message
In reality, the soldiers who took over the studios at TRT had rebuffed a civilian attempt to force them out, and the coup ringleaders were able to continue broadcasting their message.
A "Peace Council" had taken power and a curfew was in place, they said.
Another broadcaster, CNN Turk, also went off air when soldiers walked into a studio control room and social media outlets were disrupted.
But the plotters' control of media outlets was not to last and even before he had arrived at Ataturk airport President Erdogan contacted CNN Turk and appeared in a video call, urging Turks to take to the streets.
The president may have been lucky. He said the hotel where he had been staying was bombed after he had left and his secretary general had been seized.
Did the coup have widespread military support?
For the coup to have succeeded it required backing across the armed forces. A large number of soldiers may have been involved, and in several Turkish cities.
Tanks took to the streets and the bridges over the Bosphorus in Istanbul were taken over.
But the chief of staff, Gen Hulusi Akar, was not part of the coup, nor was the head of the army in Istanbul, who took command while Gen Akar was being held by the plotters.
The navy chief and special forces commander also spoke out against the uprising and F-16 fighter jets attacked some of the rebel tanks.
"This attempted coup collapsed before it even started," said Fadi Hakura of UK-based Chatham House, who said it was amateurish and failed to attract broad military support.
There was no political or public backing either. The opposition secular CHP said Turkey had seen enough coups and did not want "these difficulties repeated". The nationalist MHP also rallied behind the government.
Who were the plotters?
They are a faction within the army, and military figures say they are a small group within the First Army, whose headquarters is in Istanbul.
"They didn't represent the vast majority of the military," says Fadi Hakura, who believes their failure is evidence coups no longer enjoy the broad support they once did in Turkey.
Recep Tayyip Erdogan has long warned against potential coups and in recent years his government has attempted to purge the military and police of figures it suspects of agitating against his Islamist-rooted AK Party.
Could it have all been planned in America?
President Erdogan has for years accused a former ally, Fethullah Gulen, of plotting against him. The pair fell out and Mr Gulen went into self-imposed exile into the US.
And it did not take long for the president to blame "the parallel state", a clear reference to his rival.
The Gulen movement itself denied involvement. A pro-Gulen group said it found the attempted coup "strange and interesting" but rejected any attack on democracy, fearing renewed attacks on its movement.
However, the government quickly acted to suspend five generals and 29 colonels who they said were linked to the "parallel state", Turkish Anadolu news agency reported.