Erdogan sounded triumphant as he emerged before a sea of supporters shortly after midnight to proclaim himself ready to lead the nation for another five years.
Almost complete results from Turkey's most important election of its post-Ottoman era showed Erdogan -- in power since 2003 and undefeated in more than a dozen national votes -- falling just short of the 50-percent threshold needed to win.
"I wholeheartedly believe that we will continue to serve our people in the coming five years," the 69-year-old leader said to huge cheers.
He also claimed his Islamic ruling party and its ultranationalist allies had captured a clear majority in parliament.
Figures from the Anadolu state news agency showed Erdogan picking up 49.3 percent of the vote.
Opposition leader Kemal Kilicdaroglu was trailing with 45.0 percent -- a disappointing outcome after late pre-election polls had shown him in the lead.
Turkey's first presidential runoff in the mostly Muslim but officially secular state's 100-year history is planned for May 28.
Kilicdaroglu's camp had initially contested the vote count and claimed to be ahead.
But the 74-year-old looked slightly despondent as he faced reporters early Monday and admitted that a runoff seemed inevitable.
"If our nation says second round, we will absolutely win in the second round," he said.
"The will for change in the society is higher than 50 percent."
The lira fell against the dollar and euro on investor disappointment that Erdogan's era of unconventional economics may not be over.
Reported turnout approached 90 percent in what has become a referendum on Turkey's longest-serving leader and his Islamic-rooted party.
Erdogan has steered the nation of 85 million through one of its most transformative and divisive eras.
Turkey has grown into a military and geopolitical heavyweight that plays roles in conflicts from Syria to Ukraine.
The NATO member's footprint in both Europe and the Middle East makes the election's outcome as critical for Washington and Brussels as it is for Damascus and Moscow.
Erdogan is lionised across swathes of conservative Turkey that witnessed a development boom during his rule.
More religious voters are also grateful for his decision to lift secular-era restrictions on headscarves and introduce more Islamic schools.
"The most important thing is that we do not divide Turkey," Istanbul voter Recep Turktan told AFP after casting his ballot.
"We will carry out our duty. I say, go on with Erdogan," the 67-year-old said.
We all miss democracy
But Erdogan's first decade of economic revival and warming relations with Europe was followed by a second one filled with social and political turmoil.
He responded to a failed 2016 coup attempt with sweeping purges that sent chills through Turkish society and made him an increasingly uncomfortable partner for the West.
The emergence of Kilicdaroglu and his six-party opposition alliance -- the type of broad-based coalition Erdogan excelled at forging throughout his career -- gives foreign allies and Turkish voters a clear alternative.
A runoff in two weeks could give Erdogan time to regroup and reframe the debate.
But he would still be hounded by Turkey's most dire economic crisis since the 1990s.
Many are still also haunted by the trauma of the government's stuttering response to a February earthquake that claimed more than 50,000 lives.
"We all missed democracy," Kilicdaroglu said after voting in the capital Ankara.
Pre-election polls indicated Kilicdaroglu would win the youth vote -- nearly 10 percent of the electorate -- by a two-to-one margin.
Erdogan "can build as many tanks and weapons as he wants, but I have no respect for that as long as there is no penny in my pocket," university student Kivanc Dal said.
Courting kingmaker vote
But others showed unwavering faith in the man who broke half a century of corruption-riddled secular rule.
Nursery schoolteacher Deniz Aydemir questioned how Turkey could be ruled by a coalition of six parties -- a favourite attack line of Erdogan's during the campaign.
"Yes, there are high prices... but at least there is prosperity," the 46-year-old said.
Erdogan's campaign became increasingly tailored to his core supporters as election day neared.
He branded the opposition a "pro-LGBT" lobby that took orders from outlawed Kurdish militants and was bankrolled by the West.
He also tried to win over state sector workers by giving them massive pay raises in the months leading up to the vote.
Much of the attention will now focus on a little know independent candidate who has turned into a kingmaker by picking up five percent of the vote.
Sinan Ogan was expelled from an ultranationalist party that has since joined forces with Erdogan and entered the campaign a few months before the vote.
"We will not say if we will support this or that candidate," Ogan said Sunday. "We will hold consultations with their representatives and then decide."