A country on the edge.

Turkey’s president Recep Tayyip Erdogan is a desperate man. He is faced with turmoil at home and abroad, the Turkish lira is crashing and internationally he is in the doghouse.

Erdogan’s project, to launch his Justice and Development Party (AKP) as conservative democrats, was initially met with applause by Western and Turkish liberals when the AKP came into power 14 years ago. First the AKP turned on its military and secular opponents, who were locked up in a series of show trials from 2008 to 2013. Then the turn came to the liberals, who were purged from the parliamentary group in 2011, and after the brutal suppression of the Gezi Park demonstrations in 2013 the penny started to drop for the AKP’s European supporters.

A prominent member of the “Friends of Turkey” group in the European Parliament concluded that Islamism had replaced Kemalism and another cheerleader confessed: “Our dream of a European Turkey has turned into a nightmare and it is time for a wake-up call.” Barack Obama, who once touted “a model partnership” between the US and Turkey and considered Erdogan a moderate Muslim leader, is also disillusioned. The only one to keep the faith is Sweden’s former foreign minister, Carl Bildt, who in 2008 proclaimed “The AKP government is made up of profound European reformers.” In August, as co-chair of the European Council on Foreign Relations, Bildt called on Europe to stand up for Erdogan.

In fact, after the attempted coup in July and the widespread purge of Erdogan’s opponents, the opposite has happened. A solid majority in the European Parliament has called on the EU Commission and 28 member states to initiate a temporary freeze of the ongoing accession talks with Turkey.

There is a curious reluctance on the part of the Turkish government to carry out an in-depth investigation of the coup, but the blame has been put unequivocally on an erstwhile ally, Fethullah Gülen, a reclusive Turkish imam resident in Pennsylvania, and the cadres of his movement, which enabled Erdogan and the AKP to come to and hold power. A showdown has been in the offing for some time, particularly since Gülen’s followers in the police and judiciary brought extensive charges of corruption against government circles as well as Erdogan’s family in December 2013.

Erdogan has publicly admitted that the declaration of a state of emergency and the suspension of civil rights, which has been replaced by government by decree, has given him the power and opportunity to do things they could not do in normal times.

The results are clear. Over 92,000 have been detained, 40,000 arrested and 115,000 people have been dismissed from public service. Turkish prisons are overcrowded and there are reports of mistreatment, torture and already 25 suicides.

Since July last year Turkey has reignited its war with the PKK (Kurdistan Workers’ Party) in the southeast, and there have been terror attacks not only from the PKK but also Turkish members of ISIL. Erdogan’s overall aim, which is now within reach, is to gain parliamentary support for a constitutional change which will make him executive president but without the checks and balances of democratic rule. To this end, Erdogan has fanned the flames of nationalist sentiment and declared “the second War of Independence” (from Western influence) to undermine the legacy of the founder of modern Turkey, Mustafa Kemal Atatürk.

Erdogan has already turned his back on the Lausanne Treaty from 1923, which defined the borders of modern Turkey, and has instead invoked the Misak-i Milli (National Pact), passed by the Ottoman parliament in 1920, which laid claim to areas of Greece, Syria and Iraq. This has already led to a conflict with Iraq and the Turkish army is in northern Syria, ostensibly in support of the Free Syrian Army (FSA) in its struggle against ISIL.

A deal brokered with the EU in March to stem the flow of refugees from Turkey, which promised visa liberalisation for 80 million Turks, now appears uncertain, and Erdogan, like Muammar Gaddafi, now threatens to open the floodgates. Meanwhile, the Turkish economy, which is dependent on foreign capital, continues to tank. Moody’s has downgraded Turkey’s credit rating to junk and President Erdogan has called on Turks to change their forex into lira and gold to save the economy.

However, Erdogan’s nemesis could well be the USA. A key figure in the December 2013 corruption allegations against the Turkish government is Iranian-Turkish businessman, Reza Zarrab, who was accused of bribing ministers with millions of dollars to facilitate the export of gold to Iran to break US sanctions. Instead, Zarrab was acquitted, awarded a top exporter prize and the public prosecutors and police were removed.

In March Zarrab was arrested in Miami and indicted for sanction-busting by New York District Attorney, Preet Bharara, who has a formidable track record for prosecuting corruption cases. The Turkish government has made attempts to interfere with Zarrab’s prosecution but to no avail. Now Bharara has confirmed he has agreed to continue as US attorney “without fear or favor” at the request of President-elect Donald Trump. Zarrab’s trial is scheduled to begin in October next year, which can only add to Erdogan’s worries.

Robert Ellis is a regular commentator on Turkish affairs in the Danish and international press.