“You should not forget how you got your post,” warned President Recep Tayyip Erdogan before forcing the resignation of his prime minister, a move which pushed Turkey into a crisis which is likely to have far reaching and serious repercussions beyond its borders.

Mr Erdogan’s stricture on the price of failing to show political loyalty was given to a gathering of local officials. But the remarks were directed, it was believed, elsewhere. At a meeting soon afterwards he demanded the resignation of Ahmed Davutoglu.

Mr Davutoglu announced his resignation on Thursday. He had been a close ally of Mr Erdogan, who had promoted him into government. The departure was an illustration of the President’s dominance and, to his critics, an example of how Turkey is being ruled by a strongman who refuses to tolerate opposition and eliminates those who stand against his accumulation of ever greater power.

This was the next stage in a “hollowing out” of Turkish institutions which has already seen Mr Erdogan gain control the military and parliament, charged Soner Cagaptay, director of the Turkish Research Programme at the Washington Institute. “It shows how much power has been massed in one person’s hand,” he said, pointing out that Mr Erdogan now exercises more control than anyone in Turkey’s modern democratic history.

Mr Davutloglu, standing down, pointedly reflected that the economic and security situation called for a “prime minister who is more closely aligned with President”. The immediate effect of his resignation, however, was uncertainty in the markets, with the Turkish lira dropping four per cent in value against the dollar.

Some, including members of the ruling AKP party, had hoped that Mr Davutloglu, who commands the support of a substantial number of MPs, may mount a challenge from the outside. But the now former Prime Minister was careful to add: “No one heard, or will hear, a single word from my mouth against our President.” Observers said that the intellectual former academic had decided that he did not want to get into a bruising contest with someone like Mr Erdogan, who relishes his reputation of growing up as a political street fighter.

A “rift in the AKP might well lead to much wider and much more dangerous conflict in Turkey’s society as a whole”, said Carl Bildt, the former Swedish Prime Minister, who had been part of a number of peace building efforts worldwide.

But Turkey’s main opposition leader, Kemal Kilicdarough, wanted to stress that the Prime Minister’s fall went far beyond infighting in the ruling party. “Davutoglu’s resignation should not be perceived as an internal party issue, all supporters of democracy must resist this palace coup,” he said.

There are international ramifications to what has happened. The departure of Mr Davutoglu comes at a time when Turkey is in a central position in a critical crisis facing the international community. Ankara has agreed to take back refugees who have been arriving in their tens of thousands in Europe and is likely to get, in return, visa-free travel for its 80 million nationals in the Schengen Zone of the Continent and billions of Euros from Brussels to look after the refugees.

President Erdogan with his former Prime Minister Ahmed Davutoglu (Rex)

At the same time, Turkey is taking increasingly forward military steps in the Syrian civil war, the source of the refugee flow and is now engaged in an escalating conflict with Kurdish separatists in Turkey, Syria and Iraq. The developments are taking place against a backdrop of rising condemnation of the Turkish government over its increasingly draconian stance on human rights. Mr Erdogan’s aim of changing the constitution and installing a presidential style government would, say the opposition, further remove of him from parliamentary scrutiny.

All these issues played a part in the fall of Mr Davutoglu. The Prime Minister was being seen as the man the West could do business with as President Erdogan’s behaviour was viewed as increasingly irascible and erratic. And the most pressing business, for the European Union (EU), was the matter of refugees.

It was Mr Davutoglu who had carried out the refugee deal with Angela Merkel in March. The German Chancellor, whose open door policy is widely blamed at home and abroad for triggering the massive flow of refugees, grasped the surprise offer by the Turkish Prime Minister to take back all those who had crossed the Aegean Sea into Greece illegally – and badgered fellow EU leaders to accept Turkish demands in return.

In refugee policy, we cooperate with a few countries which are not the Eldorado of democracy <p>Martin Schulz, European Parliament president</p>

The surprise at Mr Davutoglu’s offer on the refugees extended to the Turkish President’s office, according to critics of the Prime Minister. Mr Erdogan, they claimed, was not even informed of the sweeping nature of what Turkey was about to agree to.

President Erdogan has effectively dissociated himself from this historic agreement. He was not in Gaziantep, near the Syrian border, when Mrs Merkel and Donald Tusk, the European Council president, paid a widely publicised visit to a refugee camp. It was Mr Davutoglu who was there for the Turkish government, seemingly pleased with himself over his closeness to European leaders.

President Erdogan was publicly dismissive of what Mr Davutoglu’s supporters have been hailing as a signal achievement, the likelihood of visa-free travel by June. “During my time as prime minister it was announced this would come in October 2016,” he said. “I don’t understand why brining it forward four months is presented as a win. I am saddened by the presentation of small things in a bigger light.”

Recep Tayyip Erdogan's most controversial quotes Show all 8 1 /8 Recep Tayyip Erdogan's most controversial quotes Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes Just a week before he was elected President, he called Erdogan Amberin Zaman, the Turkey correspondent for 'The Economist', a "shameless militant woman disguised under the name of a journalist" after she had asked an opposition leader whether "Muslim society is able to question" the authorities. "Know your place," Erdoğan said. "They gave you a pen and you are writing a column in a newspaper. "And then they invite you to a TV channel owned by Doğan media group and you insult at a society of 99 per cent Muslims," he said he said according to Today's Zaman newspaper. Sascha Schuermann/Getty Images Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes Turkish people are pictured chanting slogans during an anti-government protest on Taksim square in Istanbul, on 29 June, 2013. The protests were sparked by brutal police action against a local conservation battle to save Istanbul's Gezi Park, and soon turned into nationwide demonstrations against the government. Amid the protests - the worst in Turkey for years - Erdogan accused demonstrators of being "arm-in-arm with terrorism," according to Reuters. "This is a protest organized by extremist elements. We will not give away anything to those who live arm-in-arm with terrorism," he said. GURCAN OZTURK/AFP/Getty Images Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes During last year’s protests, activists used social media to organise and disseminate information. Several dozen tweeters were arrested following the protests, according to local media reports. Erdogan responded by calling the technology a "menace". "There is now a menace which is called Twitter," Erdogan said. "The best examples of lies can be found there. To me, social media is the worst menace to society," BBC New reported. Vladimir Astapkovich/RIA Novosti via Getty Images Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes Not helping to allay accusations of authoritarianism, after Turkish police detained 49 people, including well-known business people and those close to the ruling party, Erdeogan ominously told reporter that Turkey "is not a banana republic" that can be affected by unnamed "operations", according to Today's Zaman newspaper. “People who are backed by the media and certain funders cannot change this country," he said. "People backed by certain dark gangs both inside and outside Turkey cannot mess with the country's path. They cannot change conditions in Turkey. Turkey is not a country that anyone can launch an operation into. The [Turkish] nation will not allow that. The AK Party, which is governing this nation, will not allow this." Alexander Hassenstein/Getty Images Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes Friends and relatives of the miners who died in an explosion at the Soma mine are pictured praying following the burial in Soma cemetery of the last body to be recovered from the mine in May 2014. At the time, the then-Prime Minister badly misjudged the Soma mining disaster, in which 301 workers died. He told the relatives of dead and dying miners that "these types of incidents are ordinary things", following allegations that the government had ignored safety concerns about the privately owned mine, the Guardian reported. In his defence, Erdogan recounted in a separate speech a list of mining disasters which occurred abroad, including a British disaster in 1862, and one in America "which has every kind of technology". Oli Scarff/Getty Images Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes Palestinians pictured attending Friday noon prayers in a destroyed mosque that was hit by Israeli strikes, in Gaza City. As Prime Minister, Erdogan has condemned Israel, accusing it of deliberately killing Palestinian mothers and warned that the it would "drown in the blood it sheds." Speaking to thousands of supporters during a rally in Istanbul ahead of the 10 August election, Reuters reported him as saying: "Just like Hitler, who sought to establish a race free of all faults, Israel is chasing after the same target." "They kill women so that they will not give birth to Palestinians; they kill babies so that they won't grow up; they kill men so they can't defend their country ... They will drown in the blood they shed," he said. AP Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes Amid the worst protests in Turkey for years which had spread across dozens of cities last June, Erdogan accused demonstrators of being "arm-in-arm with terrorism," according to Reuters. A demonstration to halt construction in a park in an Istanbul square grew into mass protests against a heavy-handed police crackdown and what opponents called Erdogan's authoritarian policies. "This is a protest organized by extremist elements," Erdogan said before departing on a trip to North Africa. "We will not give away anything to those who live arm-in-arm with terrorism," he said. Sascha Schuermann/Getty Images Recep Tayyip Erdogan's most controversial quotes The Turkish President's craziest quotes In March 2014, Erdogan accused a 15-year-old boy who died from injuries sustained in last year's anti-government protests of being linked to terrorism. Berkin Elvan, who became a symbol of anti-government protests, had gone to pick up bread when he was hit with a teargas canister - sending him into a nine-month coma before he passed away. In a speech broadcast on state TV, Erdogan said of Berkin: "This kid with steel marbles in his pockets, with a slingshot in his hand, his face covered with a scarf, who had been taken up into terror organisations, was unfortunately subjected to pepper gas. “How could the police determine how old that person was who had a scarf on his face and was hurling steel marbles with a slingshot in his hand?” ADEM ALTAN/AFP/Getty Images

EU leaders appear to realise that the Turkish President may not be enamoured with the agreement. At the same time they face criticism for coming to an agreement with an increasingly autocratic figure. “In refugee policy, we cooperate with a few countries which are not the Eldorado of democracy,” said Martin Schulz, the European Parliament president last month. “And we made the pact not with Mr Erdogan, but with the Turkish Republic.” The fact that the pact was not with Mr Erdogan may now see it unravel.

Mr Davutoglu had also been questioning aspects of a crackdown which has seen dozens of members of the media prosecuted. The Prime Minister had been against the practice of refusing bail to journalists and putting them in prison before their trial has taken place, something on which he had received the backing of the Deputy Prime Minister, Numan Kurtulmus.

Numan Kurtulmus, Turkey's Deputy Prime Minister (Getty)

The prime minister had also suggested that he was in favour of starting negotiations with Kurdish separatists – something Mr Erdogan, who blames the PKK for breaking the ceasefire leading to the current violence, strongly opposes.

Mr Davitoglu’s lukewarm response to Mr Erdogan’s desire for a presidential system increasingly became another source of disagreement. An anonymous blog, believed to be by a pro-Erdogan journalist, accused the prime minister of conspiring with Western powers and Turkey’s enemies to undermine the President.