A Turkish woman waves a flag of her country during the speech of President Recep Tayyip Erdogan at the Democracy and Martyrs’ Rally in Istanbul. Photo / AP

Hundreds of thousands of people attended a historic pro-democracy rally organised by Turkey’s ruling party today, bringing to an end three weeks of demonstrations in support of President Recep Tayyip Erdogan after last month’s failed coup.

Istanbul’s Yenikapi Square was a sea of red and white Turkish flags with many taking part wearing headbands emblazoned with Erdogan’s name.

A huge banner declared “the victory is democracy’s, the square is the people’s”.

The grand “Democracy and Martyrs” rally was being held under tight security with 15,000 police on duty.

Followers of Erdogan’s Justice and Development Party (AKP) have taken to the streets every night since the attempted putsch on July 16 that claimed at least 273 lives including 34 coup plotters.

The rallies were not limited to Istanbul and the capital Ankara. Thousands rallied in the popular tourist spots of Izmir in the west, Antalya in the south and Diyarbakir in the restive south-east.With some media predicting that up to 3.5 million people would attend, an official from the prime minister’s office told AFP that “arrangements were made for three million people”, but could not give an immediate estimate.

Prime Minister Binali Yildirim appeared briefly on stage in Istanbul before the start of the rally, waving to the crowds after opposition party leaders arrived and shortly before Erdogan appeared with his wife, Emine Erdogan, on stage.

The crowds observed a minute’s silence before a rendition of the national anthem opened the rally followed by readings from the Koran.

A large section of VIP seats overlooking the square were reserved for families of those killed in the coup attempt.

Among those in the crowd, one man, Ramazan, aged 65, told AFP he was at the rally for his country.

“We are here today not for our leader but to protect our country,” adding that he would not let Turkey fall into the hands of “rogues”.

Wearing a hat covered in the Turkish flag on top of her headscarf, another participant, Aynur, said she hoped that the political parties would remain united after the rally.

“All the political parties are united, a picture we have longed to see. God willing, this unity will last forever,” said the AKP supporter who has also voted for the opposition CHP in the past.

Before the rally began, the names of those killed during the failed putsch were read out one by one in the presence of former President Abdullah Gul, former Prime Minister Ahmet Davutoglu and the current Chief of Staff, Hulusi Akar.

Turkey has accused reclusive US-based cleric Fethullah Gulen of masterminding the coup attempt which was led by a rogue faction in the military.

Osman Kor, aged 45, said he was attending because Kemal Kilicdaroglu, head of the secular Republican People’s Party (CHP), was attending.

“I am a CHP voter, and an advocate of left-wing principles. Our leader is here, so we are,” he said.

“Gulen movement and other religious groups (tarikat) have enslaved our country. Now is the time to stop them,” Kor added.

On the unity theme, Erdogan invited opposition leaders to address the crowds, except for the pro-Kurdish Peoples’ Democratic Party (HDP).

An AKP follower, who did not wish to be named, expressed his pleasure at the opposition’s response. “I support the AKP but I am delighted that the MHP and CHP are supporting this huge rally.”

The CHP hosted a mass pro-democracy rally last month on Istanbul’s Taksim Square which AKP supporters also attended in a show of patriotic post-coup unity.

Erdogan retaliated after the coup with a sweeping crackdown on alleged coup plotters.

Over 60,000 people from the military, judiciary, civil service and education have been dismissed, detained or put under investigation for suspected links to the Gulen movement.