The coup attempt, with or without the backing of the top generals, leaves Erdogan's power uncertain at a time when the country is beset by crises - a wave of deadly terror attacks launched by the so-called Islamic State; a wave of hundreds of thousands of refugees pouring over his borders with Iraq and Syria as they flee the war ravaging those countries; and a resurgent and bloody bid by Turkey's significant Kurdish minority for autonomy in their south-eastern territory. All of this has unfolded as Erdogan causes anger and distrust with absurd autocratic behaviour as he attempts to fold much of the executive powers of running the country into the post of president – which by tradition and law, is a titular office. President Recep Tayyip Erdogan used Facetime to speak to the Turkish people. Credit:Getty Images Given all that, there was a bit of irony in the name under which the coup leaders plotted – they called themselves Peace at Home, which is taken from a line used by the founder of the modern and secular Turkish state, Mustafa Kemal Ataturk when he said: "We work for peace at home, peace in the world. Funny enough, Erdogan opted for something similar when he came to power in 2002, dubbing his foreign policy as "zero problems with neighbours". It didn't work for the coup plotters; just as the outcome of Erdogan's regional fumbling has problems with pretty well all his neighbours. That huge crowds poured into the streets, seemingly thwarting an effort by elements of the military to take control of key cities and precincts, seemed to confirm that the president remain in power. That some senior military officers and leaders of the opposition political parties condemned the coup bid suggested that the president might well ride out the crisis.

But reports that elements of the military were ordering people to return to their homes, in defiance of Erdogan's appeal for them to join street protests suggested that the dust had yet to settle in Istanbul, Ankara and other cities. Turkish army tanks move in the main streets in the early morning hours of Saturday in Ankara, Turkey. Credit:AP The difficulty in Turkey is a history of military intervention in government. Clearly some in the officer corps have decided that the president has gone too far in grabbing all power for himself and his crony circle and that his mishandling of internal and regional conflict and crisis constituted a threat to the national interest. Regional forces are buffeting Turkey, but much of its current instability springs from two domestic struggles that Erdogan sees as particular assaults on him personally – the bloody fight by Turkey's minority Kurds for autonomy; and the political activity of the Gulen movement, which has members across government and with which Erdogan once was aligned – but now accuses of seeking to undermine his authority. Supporters of Turkish President Recep Tayyip Erdogan march in the main streets of Istanbul, in the early morning hours of Saturday. Credit:Getty Images

Erdogan knows his country's history – in the second half of the 20th century the military stepped in four times…in 1960, in 1971, in 1980 and again in 1997. Looking at those approximate 10-yearly interventions, the generals would argue that this coup is long overdue. Erdogan likes to think that the modern Turkish state is all about him. But history says it's all about Mustafa Kemal Ataturk, an Army general who modernised, secularised and westernised the modern Turkish state – of which he became the first president in 1923. The Turkish military headquarters in Ankara, Turkey, on Friday. Credit:Getty Images His effort to marginalise religion was more effective in the cities than in the country but it held because of the military's self-appointed role as guardian of the Ataturk legacy. The 1960 coup was a challenge to the then Menderes government's Cold War overtures to Moscow and its moves towards religious freedom – in 1961 by then former Prime Minister Adnan Menderes was executed.

Turkish army tanks move in the main streets of Ankara in the early morning hours of Saturday. Credit:Getty Images Democracy was restored in in the mid-1960s, but by 1971, Islamists were on the march again but were checked by a warning from the military to the government that set out very clearly the expectations of the generals in terms of the Ataturk legacy – they demanded "the formation, within the context of democratic principles, of a strong and credible government, which will neutralise the current anarchical situation and which, inspired by Ataturk's views, will implement the reformist laws envisaged by the constitution". The then prime minister knew what he had to do – he resigned. In 1980, the military ceased power for three years; in 1997, they again resorted to a coup by memo, which forced the resignation of then Prime Minister Necmettin Erbakan, without taking the levers of power itself. Tanks move into position as Turkish people attempt to stop them, in Ankara, Turkey, early on Saturday. Credit:AP Erdogan will have difficulty blaming the military this go-round, because one of his singular achievements as prime minister from 2003 to 2014 was to clean out the leadership of all the forces, in what was sold to Turks and the world as a repositioning of the military to keep it at arms length from the elected government of the country.

Hence Erdogan's naming of the Gulen movement as the cause of his discomfort. Follow Fairfax World on Facebook Follow Fairfax World on Twitter