Turkey could face new coup attempts if it does not learn from the July 15 coup attempt, Erdogan said in an address to the massive crowd.
"We will not forget, [and] will not let it be forgotten. If we do not learn the lessons from July 15, new July 15s would be inevitable," he said.
The Fetullah Terrorist Organization (FETO) and its U.S.-based leader, Fetullah Gulen, are accused of orchestrating the attempted overthrow that left 249 people martyred and nearly 2,200 injured.
Ankara has also said FETO is behind a long-running campaign to overthrow the state through the infiltration of Turkish institutions, particularly the military, police and judiciary.
The commemoration ceremony began at the July 15 Martyrs' Bridge with the national anthem, followed by a recitation of the Holy Quran.
The names of the martyrs were read aloud and their pictures were displayed on large screens erected at the venue.
Erdogan said the bridge was the scene of the bloodiest and fiercest resistance in which 36 souls were martyred. He thanked the nation for resisting the coup plotters.
But Erdogan also lambasted main opposition Republican People's Party (CHP) head Kemal Kilicdaroglu for his "controlled coup" remarks, saying Kilicdaroglu insulted martyrs and veterans of the defeated coup.
"It is disrespect [and] insult to 250 martyrs, disrespect [and] insult to 2,193 veterans; it is disrespect [and] insult to this nation," Erdogan said.
Kilicdaroglu has repeatedly claimed the government had advance knowledge of the coup plot but did nothing to prevent it.
In the wake of the failed overthrow bid, tens of thousands of FETO suspects have been arrested, including many in the armed forces, police, judicial system, education and business sectors.
Later in the ceremony Saturday, Erdogan unveiled the Monument of Martyrs near the July 15 Martyrs' Bridge to honor those who lost their lives resisting the putsch.
Erdogan also suggested suspects in FETO probes might wear uniforms when they appear before a judge.
“These are the good days of the FETO members. Recently we talked with Mr. Prime Minister. They should wear uniforms like they do at the Guantanamo [prison] while going to court.”
His remarks follow the appearance before a judge of a FETO suspect -- who was part of the group that tried to assassinate Erdogan the night of the coup -- in a t-shirt with the word “Hero” in English, that caused a public outcry.
Earlier, having gathered in Beylerbeyi, Cengelkoy, Altunizade and Kisikli districts of the Asian side of the city, demonstrators marched to the bridge amid tight security.
The bridge was closed by coup plotters on the night of the attempt.
Erdogan is scheduled to address parliament at 2.32 a.m. (2332GMT), the exact time the building was bombed on the night of the coup attempt.
Sunday's program will begin with a morning prayer at Ankara's Bestepe Millet Mosque, followed by the opening of the July 15 Martyrs' Monument at the presidential complex.