Turkey could fall foul of Nato's "requirement with respect to democracy" if it fails to uphold the rule of law in the wake of an attempted coup, the US Secretary of State John Kerry has warned.

The Turkish government's response to the failed coup has alarmed both the US and the EU, after it described the plotters as a "cancer" which had to be "cleansed" from public institutions.

A State Department spokesman has suggested it is "too soon to say" if a clampdown by the Erdogan government could jeopardise Turkey's membership of Nato.

But Nato's leadership has made it clear that a commitment to "uphold democracy, including tolerating diversity" is one of the five core requirements for members of the alliance.

Around 8,000 police officers have been suspended across Turkey following the failed coup, with more than 6,000 people in the army, the judiciary and other state bodies arrested as part of President Recep Tayyip Erdogan's response to Friday's events.

Erdogan has said the people who attempted the coup "must pay," and that the government will consider introducing the death penalty for people believed to have committed traitorous acts against the state.

At a joint news conference with EU foreign policy chief Federica Mogherini, US Secretary of State John Kerry said that America stands "squarely on the side of the elected leadership in Turkey," but that "we urge the government of Turkey to uphold the highest standards of respect for the nation's democratic institutions and the rule of law".

While Ms Mogherini warned that countries that allow the death penalty cannot join the European Union, Mr Kerry added that "Nato also has a requirement with respect to democracy," The Washington Post reported.

The US "will certainly support bringing the perpetrators of the coup to justice," he said, "but we also caution against a reach that goes beyond that and stress the importance of the democratic rule being upheld".

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

The Turkish foreign minister Mevlut Cavusoglu has insisted that President Erdogan's government will respect democracy, while Mr Kerry responded that Nato would "measure" its actions. "Obviously a lot of people have been arrested and arrested very quickly," Mr Kerry added, "The level of vigilance and scrutiny is obviously going to be significant in the days ahead. Hopefully we can work in a constructive way that prevents backsliding."

Ms Mogherini said the incident "is no excuse to take the country away from fundamental rights and the rule of law, and we will be extremely vigilant on that."

The pair spoke after a meeting in Brussels that also included the bloc's 28 foreign ministers.

US officials have since denied Mr Kerry's comments on Nato were a warning to Turkey. State Department spokesman John Kirby told the Washington Post that Nato will be watching Turkey carefully, but added it was "too soon to say" its membership was at risk.

A senior official from the US embassy in Ankara told the Daily Sabbah, "Secretary Kerry didn't say anything at all about Nato membership being in jeopardy. There is nothing in his actual statement that indicates the US believes Turkey is in a danger in this sense."

In Berlin, Chancellor Angela Merkel's spokesman said talks on Turkey's bid to the join EU would end if Ankara restores the death penalty.

Her spokesman Steffen Seibert said "the institution of the death penalty can only mean that such a country could not be a member" of the bloc.

Both Ms Mogherini and Mr Kerry reiterated the trans-Atlantic support for Turkish President Recep Tayyip Erdogan's democratically-elected government.