ByHumeyra Pamuk and Nick Tattersall, ReutersAugust 7, 2016

People hold Turkey's national flags during the Democracy and Martyrs Rally, organized by Turkish President Tayyip Erdogan and supported by ruling AK Party (AKP), oppositions Republican People's Party (CHP) and Nationalist Movement Party (MHP), to protest against last month's failed military coup attempt, in Istanbul, Turkey, August 7, 2016.

ISTANBUL — Hundreds of thousands of Turks began gathering in Istanbul on Sunday summoned by President Tayyip Erdogan to denounce a failed coup - a show of strength staged in the face of Western criticism of widespread purges and detentions.

The "Democracy and Martyrs' Rally" at the Yenikapi parade ground, built into the sea on the southern edge of Istanbul's historic peninsula, caps three weeks of nightly demonstrations by Erdogan's supporters, many wrapped in the red Turkish flag, in squares around the country.

The vast majority of those gathering for the rally were Erdogan supporters, some with banners reading "You are a gift from god, Erdogan" or "Order us to die and we will do it."

"We're here to show that theses flags won't come down, the call to prayer won't be silenced, and our country won't be divided," said Haci Mehmet Haliloglu, 46, a civil servant who traveled from the Black Sea town of Ordu for the rally.

"This is something way beyond politics, this is either our freedom or death," he said, a large Turkish flag over his shoulder and a matching baseball cap on his head.

Mr. Erdogan has vowed to rid Turkey of the network of U.S.-based cleric Fethullah Gulen, whose followers in the security forces, judiciary and civil service he accuses of orchestrating the attempted power grab and of plotting to overthrow the state.

The cleric was an ally of Erdogan in the early years after his AK Party was elected in 2002. He has denied the charges and denounced the coup which came at a critical time for NATO "frontline" state Turkey, facing as it does islamist militant attacks from across the border in Syria and from Kurdish rebels.

Tens of thousands of people have been suspended, detained or placed under investigation since the plot - including soldiers, police, judges, journalists, medics and civil servants - prompting concern among Western allies that Erdogan is using the events to tighten his grip on power.

"The triumph is democracy's, the squares are the people's," said flyers put through doors overnight advertising free bus, ferry and subway transport to Sunday's rally. The slogan adorns banners hung from bridges and buildings across the country.

Erdogan, accused by critics in the past of dividing the country by an intolerance of criticism, has invited the heads of the secularist and nationalist opposition to address the crowds in what he hopes will show a unified nation in defiance of Western criticism.

"The only way to eliminate coups is to revive the founding values of the Republic. These values that make our unity should be spoken out loud at Yenikapi," said Kemal Kilicdaroglu, leader of the secularist opposition CHP, in a tweet ahead of the rally.

The brutality of July 15, in which more than 230 people were killed as rogue soldiers commandeered fighter jets, helicopters and tanks, shocked a nation that last saw a violent military power grab in 1980. Even Erdogan's opponents saw his continued leadership as preferable to a successful coup renewing the cycle of military interventions that dogged Turkey in the second half of the 20th century.

Secularists and nationalists who oppose Erdogan also loathe Gulen's Hizmet (Service) network, used by Erdogan in years past to help undermine the power of secularist generals suspicious of his ruling AK Party's Islamist ideals. They have so far been limited in their criticism of purges of alleged Gulenists, though they have raised questions about the pace and scale of the detentions.

Such solidarity may not last.

There are already opposition concerns that the restructuring of the military is happening without parliamentary oversight and is going too far, with thousands of soldiers discharged including around 40 percent of generals.

WESTERN CRITICISM

Erdogan said this week he had initially misread the intentions of Mr. Gulen, whose network was once close to the AKP, and asked: "May my people and God forgive me."

"He is such a big leader that he can admit his mistake. No president has ever apologized to his people before," said Gurkan Cendeli, 21, a student from the southern city of Adana who slept outside the presidential palace in Ankara on Saturday night with a group of friends before taking an overnight bus to Istanbul.

"Ready for your order, commander-in-chief," read the slogan on his T-shirt.

The extent of the purges in Turkey, which has NATO's second largest armed forces and aspires to membership of the European Union, have drawn criticism in the West.

In comments published on Sunday, the leader of Germany's liberal Free Democrats (FDP) said he saw parallels between Erdogan's behavior and the aftermath of the Reichstag fire in 1933, portrayed by the Nazis as a Communist plot against the government and used by Adolf Hitler to justify massively curtailing civil liberties.

Turkish officials have angrily rejected suggestions that the purges are out of proportion, accusing Western critics of failing to grasp the magnitude of the threat to the Turkish state and of being more concerned about the rights of coup plotters than the brutality of the events themselves.

So damaged are relations that Germany's foreign minister said this week "we are talking with each other like emissaries from two different planets." Austria's chancellor suggested talks on Turkish EU membership should be suspended. (Additional reporting by Tuvan Gumrukcu in Istanbul, Caroline Copley in Berlin; Writing by Nick Tattersall; editing by Ralph Boulton)