President Tayyip Erdogan's opponents face an uphill struggle to end his two-decade rule of Turkey in a runoff vote on May 28 after he performed better than predicted in a first round of voting on Sunday but fell short of an outright majority.
Turks woke on Monday to see support for Erdogan just below the 50 per cent threshold needed to avoid sending the NATO-member country to a second round of a presidential election viewed as passing judgement on his autocratic rule.
Pro-government media cheered the outcome, with Yeni Safak newspaper proclaiming "The people won", referring to Erdogan's People's Alliance that appeared to have won a majority in parliament, potentially giving him a crucial edge in the presidential runoff.
"The winner has undoubtedly been our country," Erdogan said in a speech to his cheering supporters at the headquarters of his ruling AK Party in the capital Ankara overnight.
Going into the election, the opposition had sensed its best chance yet of unseating Erdogan, encouraged by polls showing him trailing his main challenger Kemal Kilicdaroglu. But the results suggested Erdogan and his AK Party had been able to rally conservative voters despite a cost-of-living crisis.
Kilicdaroglu, head of a six-party alliance, vowed to prevail in the runoff and accused Erdogan's party of interfering with the counting and reporting of results, calling on his supporters in the country of 84 million to be patient.
The prospect of Erdogan's rule entering a third decade will upset civil rights activists campaigning for reforms to undo the damage they say he has done to Turkey's democracy.
Thousands of political prisoners and activists could be released if the opposition prevails.
Turkey's main share index tumbled 6.4 per cent in pre-market trading, with the banking index down 9.5 per cent. Turkey's main share index tumbled 6.4 per cent in pre-market trading, with the banking index down 9.5 per cent.
With 99 per cent of ballot boxes counted, Erdogan led with 49.35 of votes and Kilicdaroglu on 45 per cent, according to state-owned news agency Anadolu. Election turnout was a high 88.8 per cent.
A third candidate, the nationalist Sinan Ogan took some 5.2 per cent of the vote and analysts said he could play a "kingmaker" role in the runoff if he decides to endorse one of the two.
Galip Dalay, associate fellow at Chatham House, said Erdogan's ruling alliance would go into the second round "with numeric and psychological advantages".
Turkey's longest-serving leader has turned the country into a global player, transforming it with huge infrastructure projects such has airports and bridges and building a defence industry attracting many foreign customers.
The political uncertainty was expected to weigh on financial markets in the next two weeks. Overnight the lira hit a new two-month low against the dollar, weakening to 19.70 before edging back to 19.645 by 0600 GMT.
The cost of insuring against Turkey defaulting on its sovereign debts surged to a six-month high, jumping 105 basis points (bps) from Friday's levels to 597 bps, according to S&P Global Market Intelligence.
The mood at the opposition party's headquarters had been subdued overnight as the votes were counted. Before the election, opinion polls had put Kilicdaroglu slightly ahead, with two polls on Friday showing him above the 50 per cent threshold.
The opposition had expected to benefit from voter anger at economic woes after an unorthodox policy of low-interest rates triggered a lira crisis and soaring inflation. A slow response government response to the earthquake that killed 50,000 people in February had also been expected to influence voters.
Kilicdaroglu has pledged to revive democracy after years of state repression, return to orthodox economic policies, empower institutions that lost autonomy under Erdogan and rebuild frail ties with the West.
Critics fear Erdogan will govern ever more autocratically if he wins another term. The 69-year-old president, a veteran of a dozen election victories, says he respects democracy.