With 97.7% of the votes counted, the electoral board pronounced the 64-year-old as the victor with an absolute majority.
The president, who has already ruled Turkey unopposed for 16 years, will be sworn in to another five years in power, leading up to the centennial of the modern republic's founding from the ashes of the Ottoman empire.
"The fact that I was forced to campaign in detention conditions was the greatest injustice", Demirtas said.
Mr Erdogan polled almost 53% in the most fiercely fought election in years. "In my name and in Turkey's name, I thank them".
Election turnout nationwide was very high at around 87 per cent for both contests, the state broadcaster said.
An unfair media landscape and reports of harassment against the HDP marked the campaign, according to an interim report from the Organization for Security and Cooperation in Europe, which sent election observers to Turkey. Sunday's vote ushers in a powerful new executive presidency long sought by Erdogan and backed by a small majority of Turks in a 2017 referendum.
The shift will give Erdogan more power in his next term, abolishing the prime minister's post, and eliminating numerous checks and balances created to help parliament protect against the misuse of presidential powers.
State media also reported on Sunday that Erdogan's AK Party holds 43 percent, while the opposition party holds 23 percent of the vote, with 96 percent of the total vote counted.
Ankara, however, says the moves are in line with the rule of law and aimed at removing the supporters of Fethullah Gulen - a US-based self-exiled religious leader blamed for the putsch - from state institutions and other parts of society.
This means his party is short of a parliamentary majority and will need to negotiate deals with allies in order to control the 600-seat house.
Although Erdogan dominated airtime on a pliant mainstream media, Ince finished his campaign with eye-catching mass rallies, including a mega meeting in Istanbul on Saturday attended by hundreds of thousands of people. The Turkish lira has eroded from 2.14 to the dollar when Erdoğan was first elected president in August 2014, to 4.68 to the dollar today, and a serious policy response is needed.
Speaking on national television, Erdogan said: "The nation has entrusted to me the responsibility of the presidency and the executive duty".
"The message is clear", he said. If no one gets over 50% of support, a runoff election will be held.
In his victory speech, Erdogan said he would work toward achieving his goal of making Turkey one of the world's top 10 economies by 2023, when the Turkish Republic marks its centenary.
"With the presidential system, Turkey is seriously raising the bar, rising above the level of contemporary civilizations", he said.
"Turkey made its choice in favour of a more determined fight against the PKK (Kurdistan Workers Party) and (Gulenists)", Erdogan said.
He added that the alliance led by the AKP had won the majority in parliament. But democracy and secularism have steadily been eroded under Erdogan.
With election victory in hand, Erdogan will rule with new muscle provided by sweeping changes to the constitution that were approved by a narrow majority of the electorate in a controversial referendum that he championed a year ago.
Other authoritarian leaders - including Iranian President Hassan Rohani, Kazakhstan's Nursultan Nazarbaev, Azerbaijan's Ilham Aliyev, Venezuela's Nicolas Maduro, and Sudan's Omar al-Bashir - congratulated Erdogan.
The 54-year-old politician criticized Turkey's new system, saying: "Turkey has cut off its links with democracy".