Turkey's presidential election will go to a run-off after the two main candidates failed to clear the 50% threshold needed to avoid a second round.
With 99.4% of the domestic votes and 84% of the overseas votes counted, Recep Tayyip Erdogan had 49.4% of the votes and Kemal Kilicdaroglu had 45%.
A third candidate, nationalist politician Sinan Ogan, received 5.2%.
The run-off will be held on 28 May, electoral chief Ahmet Yener said.
Speaking to supporters in Ankara, Mr Erdogan said he would respect the nation's decision if the race went to a run-off.
He said: "If our nation has made its choice in favour of the second round of the election, then that is also welcome.
"We strongly believe that we will continue to serve our nation for the next five years."
His rival Mr Kilicdaroglu thanked voters, noting particularly high participation among young people and women.
He added: "Despite all his slanders and insults, Erdogan did not get the result he expected.
"No one should look for a fait accompli. Elections are not won on balconies.
"The data is still coming in. If our nation says 'a second round', we welcome that.
"Our people should be certain that we will absolutely, absolutely win, and we will bring democracy to this country."
Mr Erdogan, 69, who has been in charge of the country for 20 years, is seeking a third consecutive term as president, but Mr Kilicdaroglu has presented him with his toughest ever challenge.
Opinion polls before the election had given Mr Kilicdaroglu, who heads a six-party alliance, a slight lead, and two polls on Friday even showed him above the 50% threshold.
However, most had suggested a tight margin.
Turkey's voters have also been electing parliamentarians to their 600-seat assembly.