TURKEY’S president has spoken with Russian President Vladimir Putin following the failed military coup attempt in which at least 265 people died.

A statement from President Recep Tayyip Erdogan’s office reported that Putin said Moscow stood by “Turkey’s elected government” and expressed his good wishes to the Turkish people.

It said the two leaders – who recently patched up relations following Turkey’s downing of a Russian warplane – also agreed to meet face-to-face next month.

Meanwhile, Turkey’s justice minister Bekir Bozdag said some 6,000 people had been detained in a government crackdown on alleged coup plotters and government opponents.

Bozdag said he was confident the United States would return Islamic cleric Fethullah Gulen to Turkey.

The Turkish president has blamed Gulen and his followers for the failed military coup on Friday night, but Gulen denies any involvement in or knowledge about the attempted coup. The US says it will look at any evidence Turkey has to offer against Gulen, and judge accordingly.

Bozdag said: “The United States would weaken itself by protecting him. It would harm its reputation. I don’t think that at this hour, the United States would protect someone who carried out this act against Turkey.”

Prayers were being read simultaneously from Turkey’s 85,000 mosques to rally the country to defend its democracy and honour those who died in an attempted military coup.

Three of the country’s top generals have already been detained, alongside hundreds of soldiers. The government also dismissed nearly 3,000 judges and prosecutors from their posts, and investigators are preparing court cases to send the conspirators to trial on charges of attempting to overthrow the government.

The botched coup, which saw warplanes fly over key government installations and tanks roll up in major cities, ended within hours when loyal government forces including military and police regained control of the military, and civilians took to the streets in support of Erdogan.

At least 265 people were killed and more than 1,400 were wounded. Government officials said at least 104 conspirators were killed.

Chanting, dancing and waving flags, tens of thousands of Turks marched through the streets to defend democracy and support the country’s long-time leader.

It was an emotional display by Turks, who rallied in headscarves and long dresses, T-shirts and work boots, some walking hand in hand late on Saturday and early on Sunday with their children.

Rather than toppling Turkey’s strongman president, the attempted coup appears to have bolstered Erdogan’s popularity and tightened his grip on power.

Gozde Kurt, a 16-year-old student at the rally in Istanbul, said: “Just a small group from Turkish armed forces stood up against our government ... but we, the Turkish nation, stand together and repulse it back.”

The Yeni Safak newspaper used the headline “Traitors of the country,” while the Hurriyet newspaper declared “Democracy’s victory.”

Prime Minister Binali Yildirim said the perpetrators of Friday’s failed coup “will receive every punishment they deserve”.

However, the government crackdowns raised concerns over the future of democracy in Turkey, which has long prided itself on its democratic and secular traditions despite being in a region swept by conflict and extremism.

Erdogan’s survival has turned him into a “sort of a mythical figure” and could further erode democracy in Turkey, said Soner Cagaptay, director of the Turkish research program at The Washington Institute.

“It will allow him to crack down on liberty and freedom of association, assembly, expression and media in ways that we haven’t seen before,” he said.

The coup attempt started with tanks rolling on Friday night into the streets of Ankara and Istanbul as the president was on a seaside break.

Explosions and gunfire erupted throughout the night, but it quickly became clear that the military was not united in the effort to overthrow the government.

In a dramatic iPhone interview on TV, Erdogan urged his supporters into the streets to confront the troops and tanks, and forces loyal to the government began reasserting control.

Before the chaos, Turkey – a Nato member and key Western ally in the fight against Daesh – was wracked by political turmoil that critics blamed on Erdogan’s increasingly authoritarian rule.

He has shaken up the government, cracked down on dissidents, restricted the news media and renewed fighting with Kurdish rebels.

Erdogan later vowed to purge all state institutions of supporters of Gulen.

Speaking at a funeral in Istanbul yesterday, he pledged to “clean all state institutions of the virus” of Gulen supporters.

Erdogan said Turkey, through the justice ministry and foreign ministry, would request the extradition of the cleric from the US.

Crowds chanted “Fethullah will come and pay”, ‘’Allah is Great” and “We want the death penalty”.

Erdogan said that in democracies “you cannot push the wish of the people to one side,” but also said: “we are not after revenge”.

Turkish Airlines has been forced to cancel 196 flights in and out of Istanbul due to the attempted coup.