Mr Erdogan praised those people, including MPs, who had defended democracy and his government.
He backed the death penalty for coup plotters and said they should wear Guantanamo Bay-style uniforms.
Nearly 250 people died and 2,196 were wounded fighting the coup attempt by an army faction on 15 July last year.
The government has since led a crackdown on alleged coup supporters, with the dismissal of more than 150,000 state employees and the arrest of some 50,000 people.
The coup failed for several reasons, including a lack of support in higher echelons of the armed forces and a lack of political or public backing.
Plotters tried to detain Mr Erdogan as he holidayed in an Aegean resort, but he had left and the coup was thwarted by civilians and soldiers loyal to the president. It is on these people that the president has focused in commemorations.
"People that night did not have guns, they had a flag and more importantly, they had their faith," he told thousands of supporters.
However, the national unity that was initially felt against the coup has faded, and divisions have widened, correspondents say.
Opponents of Mr Erdogan boycotted the day and night of speeches and pageantry. They say his government's actions over the past year amount to an attempt to purge dissent.
Such purges continued right up to last Friday, when more than 7,000 state employees were dismissed.
Mr Erdogan addressed Turks who had rallied to the bridge over the Bosphorus where civilians had confronted pro-coup soldiers last year.
He said: "I am grateful to all members of my nation who defended their country."
Mr Erdogan said that 250 people had lost their lives but the country had won its future.
"Putschists who closed off the bridge on that night wanted to show the world that they were in control," he said, but were countered by "millions who took to the streets that night to defend the honour of their nation".
He said he would "break the heads of the traitors" who plotted the coup.
Mr Erdogan also said he had spoken to Prime Minister Binali Yildirim about the coup plotters, saying: "When they appear in court, let's make them appear in uniform suits like in Guantanamo."
The president then unveiled a "martyrs' memorial" at the bridge, which has been renamed the Bridge of the Martyrs of July 15.
Moving on to Ankara, the capital, he spoke in parliament a year to the hour after it was bombed by warplanes.
He said that on the night of the coup, "our nation showed the whole world what a nation we are".
One supporter in the crowd, who gave his name only as Murat, said: ""If it happened again, I would stay out again. That night, it was like a war. We take ownership of this country and this people."
The date of 15 July has been declared an annual holiday called Democracy and National Unity Day.
Earlier Mr Yildirim told a special session of parliament that 15 July 2016 was a "second War of Independence", following the conflict that led to the creation of the modern state in the 1920s.
"It has been exactly one year since Turkey's darkest and longest night was transformed into a bright day, since an enemy occupation turned into the people's legend," the prime minister said.
But Kemal Kilicdaroglu, the head of the main opposition Republican People's Party, said: "This parliament, which withstood bombs, has been rendered obsolete and its authority removed.
"In the past year, justice has been destroyed. Instead of rapid normalization, a permanent state of emergency has been implemented."