President Tayyip Erdogan has extended his two decades in power after Turkey's presidential election, winning a mandate to pursue increasingly authoritarian policies which have polarised Turkey and strengthened its position as a regional military power.
His challenger, Kemal Kilicdaroglu, called it "the most unfair election in years" but did not dispute the outcome.
Official results showed Kilicdaroglu won 47.9 per cent of the votes to Erdogan's 52.1 per cent, pointing to a deeply divided nation.
Sunday's election had been seen as one of the most consequential yet for Turkey, with the opposition believing it had a strong chance of unseating Erdogan and reversing his policies after his popularity was hit by a cost-of-living crisis.
Instead, victory reinforced his image of invincibility, after he had already redrawn domestic, economic, security and foreign policy in the NATO member country of 85 million people.
The prospect of five more years of his rule was a major blow to opponents who accused him of undermining democracy as he amassed ever more power - a charge he denies.
In a victory speech in Ankara, Erdogan pledged to leave all disputes behind and unite behind national values and dreams but then switched gears, lashing out at the opposition and accusing Kilicdaroglu of siding with terrorists without providing evidence.
He said releasing former pro-Kurdish party leader Selahattin Demirtas, whom he branded a "terrorist," would not be possible under his governance.
Erdogan said inflation was Turkey's most urgent issue.
Kilicdaroglu's defeat will likely be mourned by Turkey's NATO allies which have been alarmed by Erdogan's ties to Russian President Vladimir Putin, who congratulated his "dear friend" on his victory.
US President Joe Biden wrote on Twitter: "I look forward to continuing to work together as NATO Allies on bilateral issues and shared global challenges."
US relations with Turkey have been impeded by Erdogan's objection to Sweden joining NATO as well as Ankara's close relationship with Moscow and differences over Syria.
Addressing jubilant supporters earlier from atop a bus in Istanbul, Erdogan, 69, said "the only winner today is Turkey".
"I thank every single one of our people who once again gave us the responsibility to govern the country five more years," he said.
He noted that Monday marks the 570th year of conquest of Istanbul by the Ottoman Empire.
"That was a turning point in history, closed a century and opened a new one," he told the crowd.
"I hope these elections will be such a turning point in history.”
Erdogan's victory extends his tenure as the longest-serving leader since Mustafa Kemal Ataturk established modern Turkey from the ruins of the Ottoman Empire a century ago - a politically potent anniversary to be marked in October with Erdogan in charge.
Erdogan, head of the Islamist-rooted AK Party, appealed to voters with nationalist and conservative rhetoric during a divisive campaign that deflected attention from deep economic troubles.
In his victory speech, he attacked the opposition again, calling them pro-LGBT.
Kilicdaroglu, who had promised to set the country on a more democratic and collaborative path, said the vote showed people's will to change an authoritarian government. "All the means of the state were laid at the feet of one man," he said.
French President Emmanuel Macron offered congratulations, saying France and Turkey had "huge challenges to face together".
The presidents of Iran, Israel, and the Saudi king were among leaders to congratulate him in the Middle East, where Erdogan has asserted Turkish influence, at times with military power. Erdogan, who was for years at odds with numerous governments in the region, has taken a more conciliatory stance in recent years.
Belarus President Alexander Lukashenko, Putin's staunchest ally among ex-Soviet states, offered his congratulations, praising Erdogan for maintaining stability after earthquakes earlier this year.
with DPA