The United Nations has warned Turkey that wide-ranging purges and arrests following a failed coup “go beyond what can be justified” and may violate international law.

Recep Tayyip Erdogan’s government has launched a wide-ranging crackdown since a military faction attempted to oust the president last month, arresting tens of thousands of people and removing many more from their posts.

More than 130 media outlets have been shut down, with dozens of journalists detained, while prisoners have reported torture and abuse.

Turkey’s failed coup strains relations with the West

A group of experts from the Office of the UN High Commissioner for Human Rights (OHCHR) criticised purges in the military, media, education and justice sectors.

“While we understand the sense of crisis in Turkey, we are concerned that the government’s steps to limit a broad range of human rights guarantees go beyond what can be justified in light of the current situation,” they said in a joint statement.

“Turkey is going through a critical period. Derogation measures must not be used in a way that will push the country deeper into crisis.”

Mr Erdogan has blamed a network led by Fethullah Gulen, a cleric who lives in self-imposed exile in the US, for the failed rebellion that left hundreds dead.

Authorities have arrested or suspended tens of thousands of police, troops, officials, judges and bureaucrats alleged to have linked to his “Hizmet” movement, which has denied involvement.

In pictures: Turkey coup attempt Show all 17 1 /17 In pictures: Turkey coup attempt In pictures: Turkey coup attempt Turkish President Erdogan attends the funeral service for victims of the thwarted coup in Istanbul at Fatih mosque on July 17, 2016 in Istanbul, Turkey Burak Kara/Getty Images In pictures: Turkey coup attempt Soldiers involved in the coup attempt surrender on Bosphorus bridge with their hands raised in Istanbul on 16 July, 2016 Gokhan Tan/Getty In pictures: Turkey coup attempt A civilian beats a soldier after troops involved in the coup surrendered on the Bosphorus Bridge in Istanbul, Turkey, 16 July, 2016 REUTERS/Murad Sezer In pictures: Turkey coup attempt Surrendered Turkish soldiers who were involved in the coup are beaten by a civilian Reuters In pictures: Turkey coup attempt Soliders involved in the coup attempt surrender on Bosphorus bridge Getty In pictures: Turkey coup attempt Supporters of Turkish President Recep Tayyip Erdogan wave flags as they capture a Turkish Army vehicle Getty In pictures: Turkey coup attempt People pose near a tank after troops involved in the coup surrendered on the Bosphorus Bridge in Istanbul, Turkey, 16 July, 2016 Reuters In pictures: Turkey coup attempt Turkish soldiers block Istanbul's Bosphorus Brigde Getty In pictures: Turkey coup attempt A Turkish military stands guard near the Taksim Square in Istanbul Reuters In pictures: Turkey coup attempt Pierre Crom/Twitter In pictures: Turkey coup attempt Turkish soldiers secure the area as supporters of Recep Tayyip Erdogan protest in Istanbul's Taksim square AP In pictures: Turkey coup attempt People demonstrate in front of the Republic Monument at the Taksim Square in Istanbul Murad Sezer/Reuters In pictures: Turkey coup attempt Turkish soldiers detain police officers during a security shutdown of the Bosphorus Bridge Reuters In pictures: Turkey coup attempt Turkish Army armoured personnel carriers in the main streets of Istanbul Getty In pictures: Turkey coup attempt Chaos reigned in Istanbul as tanks drove through the streets EPA/TOLGA BOZOGLU In pictures: Turkey coup attempt Turkish President Tayyip Erdogan speaks to media in the resort town of Marmaris Reuters In pictures: Turkey coup attempt Supporters of President Erdogan celebrate in Ankara following the suppression of the attempted coup Reuters

A total of 40,029 people have been detained in investigations following the coup, and 20,355 of them formally arrested, Prime Minister Binali Yildirim said on Wednesday. Several thousand companies and institutions suspected of having financed Mr Gulen have also been shut. But the UN raised concern that the measures were being used to target dissent and criticism.

Turkish authorities gained increased powers with the declaration of a national state of emergency on 20 July, and the country is now invoking Article 4 of the International Covenant on Civil and Political Rights (ICCPR), which allows it to temporarily relax laws on public freedoms.

The UN group, comprised of 19 special rapporteurs and three working groups, said the government was using “wide and indiscriminate administrative powers that affect core human rights".

"The invocation of Article 4 is lawful only if there is a threat to the life of the nation, a condition that arguably is not met in this case,” they noted.

Pro-government supporters demonstrating after the coup (Alkis Konstantinidis/Reuters)

“One cannot avoid, even in times of emergency, obligations to protect the right to life, prohibit torture, adhere to fundamental elements of due process and non-discrimination, and protect everyone’s right to belief and opinion.”

Turkey has also invoked a similar clause enabling it to violate obligations under the European Convention on Human Rights.

As well as cracking down on alleged coup supporters, authorities are fighting Kurdish militants in the south east and responding to a series of Isis terror attacks.

Mr Erdogan sought to link the Kurdistan Workers Party (PKK) and Hizmet on Thursday, in the wake of a series of bombings that killed at least 10 people and injured 300 more.

“You don't have to be fortune teller to see that the Hizmet movement is behind the latest PKK attacks in terms of sharing information and intelligence,” he said.

At the scene of a car bombing that killed three police officers in the city of Elazig, Mr Yildirim, vowed to “raise the state of alert to a higher level”.