Tens of thousands of people gathered at a massive rally in Istanbul, marking one year since the defeat of the coup aimed at overthrowing President Recep Tayyip Erdogan.

Joining the crowd gathered on Saturday at the Bosphorus Bridge, now known as the July 15 Martyrs' Bridge, Erdogan threatened to "chop off the heads" of those involved in the coup.

"First of all we will chop off the heads of those traitors," Erdogan said as he reaffirmed previous comments to sign any bill passed restoring capital punishment.

READ MORE: Middle Eastern supporters of Turkey's failed coup

"We are a state governed by rule of law. If it comes to me after parliament, I will sign it," he said. Restoring the death penalty would effectively end Turkey's European Union membership ambitions.

Erdogan also praised the "people's faith" in facing up the armed coup plotters.

Erdogan arrived from the capital Ankara on his official plane accompanied by an F-16 fighter jet, AFP news agency reported.

The authorities declared July 15 an annual national holiday of "democracy and unity", billing the foiling of the putsch as a historic victory for Turkish democracy.

"It's one year since the darkest night was turned into an epic," Binali Yildirim, Turkey's prime minister, told a special session of parliament that kicked off a day of celebrations set to last until dawn.

He said the night of July 15 was a "second War of Independence" after the war that led to the creation of the modern Turkish state in the ruins of the Ottoman Empire in 1923.

About 249 people, not including the plotters, were killed when a disgruntled faction of the army sent tanks into the streets and war planes into the sky in a bid to overthrow Erdogan.

But they were thwarted within hours as the authorities regrouped and people poured into the streets in support of Erdogan, who blamed followers of his ally turned nemesis, the US-based preacher Fethullah Gulen.

Tens of thousands carried the Turkish flag while others brandished pictures of the "martyrs" who died defeating the coup bid as a sea of people stretched from the bridge.

People chanted "we are soldiers of Tayyip [Erdogan]" and called for the reinstatement of the death penalty for the coup plotters, with some even brandishing nooses.

At 21:00 GMT, people across Turkey took part in "democracy watches", rallies commemorating how people poured out into the streets.

'Post-coup purge'

In the wake of the failed coup bid, authorities embarked on the biggest purge in Turkey's history, arresting 50,000 people and sacking almost three times as many.

Erdogan also shored up his position by winning a referendum on enhancing his powers earlier this year.

In the latest dismissals, another 7,563 police, soldiers and other state employees were fired late on Friday under the state of emergency that has been in place since July 20 last year.

Turkey's opposition put political disputes aside on the night of the putsch.

Erdogan, who was present at the session, gazed down stonily from the VIP balcony.

Erdogan later returned to Ankara and, at 23:00 GMT, gave a speech to parliament to mark the time the building was bombed last year.

Al Jazeera's Sinem Koseoglu, reporting from Ankara, said Erdogan, in his speech in front of parliament, said the fight against treason would continue.

"In front of the parliament, the president emphasised its importance. He also said they will continue efforts to clean the institution of the Gulen group within the state," she said.

"Erdogan also named the coup plotters as traitors, saying the fight against treason will continue."

The coup bid also frayed ties between the US and European Union with NATO member Turkey, which accused its allies of failing to show solidarity.

Gulen has always denied involvement and, in a new statement on Friday that condemned the "witch-hunt" of Erdogan's critics, dismissed the accusations as "baseless, politically motivated slanders".