Turkey's battle for the presidency looks almost certain to go to a run-off, with President Recep Tayyip Erdogan set for a four-point lead in the first round.
After 20 years in power, he stood on the balcony of his party HQ saying he was convinced he would win five more.
Opposition challenger Kemal Kilicdaroglu also claimed to have victory in his grasp.
Everything appeared to have fallen into place for first-round success.
But incomplete results give him around 45%, with Mr Erdogan on more than 49% of the vote. Candidates need more than 50% to win in the first round.
And Mr Erdogan has an added boost as he seeks to extend his presidency. His People's Alliance of parties has also won a majority in parliament, according to preliminary figures provided by the state news agency.
For months, Turkey's disparate opposition parties had pooled their resources in a bid to bring an end to a president who has extended his power dramatically since a failed coup against him in 2016.
The election is being watched very closely in the West, because Mr Kilicdaroglu has promised to revive Turkish democracy as well as relations with its Nato allies. On the other hand, President Erdogan's Islamist-rooted government has accused the West of plotting to bring him down.
In the early hours of Monday, Mr Kilicdaroglu stood on a stage at his party headquarters in Ankara, flanked by his allies, doing his best to sound upbeat.
"If our nation says second round, we will absolutely win in the second round," he said.
Supporters outside party headquarters chanted one of his slogans, "everything will be all right", but it was not clear for them that it would.
He had earlier angrily accused the government of seeking to "block the will of the people", by launching repeated challenges in opposition strongholds. Two rising stars in the party, the mayors of Istanbul and Ankara, reminded voters that this was a strategy that Mr Erdogan's AK Party had used before.
They praised an enormous team of opposition volunteers guarding ballot papers to ensure nothing untoward happened to the votes.
Mr Kilicdaroglu, 74, has lost several elections as leader of his Republican People's Party, but this time his message of scrapping the president's excessive powers struck a chord.
Turks have also been reeling from a cost-of-living crisis with 44% inflation, made only worse by Mr Erdogan's unorthodox economic policies.
And then the Erdogan government was blamed for a slow rescue response to the double earthquakes in February which killed more than 50,000 people in 11 provinces.
And yet, despite a very difficult few months, Turkey's dominant president appears to have the upper hand.
Overnight results suggest the president's support in eight party strongholds hit by the earthquake dipped by just two to three points.
In seven of those eight cities, his support remained above 60%. Only in Gaziantep did it slip to 59%.
Addressing supporters from the balcony he had used for previous victories he announced that "even though the final results are not in, we are far ahead".
He is also heading for a majority in parliament, along with his nationalist MHP ally, according to unconfirmed results quoted by state news agency Anadolu. Of the 600 seats in parliament, the AKP and nationalist ally MHP have 316, it says.
His supporters ridiculed the opposition allies first for declaring that Mr Kilicdaroglu would become the 13th Turkish president, and then for gradually lowering their expectations as the night progressed.
What this result does confirm is the extent to which Turkish society has become polarised, 100 years since Kemal Ataturk's foundation of the modern Turkish republic.
In the final hours before voting began, Mr Kilicdaroglu rounded his campaign off with a trip to Ataturk's mausoleum in Ankara.
President Erdogan instead chose to make a very symbolic statement to his conservative and nationalist support base, by making a campaign speech at Hagia Sophia in Istanbul.
Under the Ottomans the former Orthodox Christian cathedral had become a mosque. Ataturk had turned it into a museum, but in 2020 Mr Erdogan turned it back into a mosque, defying international criticism.
It is unclear how close the expected run-off will be, and there is already considerable speculation over what will happen to the 5% of votes that went to the third candidate in the election, ultranationalist Sinan Ogan.
He knows both leaders will be trying to court him and is bound to set some tough conditions.
It is far from certain that even if he does endorse either candidate the first-round voters he attracted will do the same.
<p>In an interview, British Defense Secretary Ben Wallace says the alliance must press its members to spend more on defense if Russia is to be contained</p>