Image copyright AFP/Getty Images Image caption President Erdogan and his wife Emine greet supporters at his party's Ankara HQ
Turkey's long-standing leader Recep Tayyip Erdogan has won a new five-year term after securing outright victory in the first round of a presidential poll.
Mr Erdogan got nearly 53% with almost all votes counted. His closest rival Muharrem Ince was on 31%.
He will now assume sweeping new powers, won in a controversial referendum last year. The post of PM will be abolished.
Mr Ince accepted the result on the basis of poll figures - but said that everything about the vote was unfair.
Final results will be announced on Friday.
The polls were the most fiercely fought in many years.
Mr Erdogan has presided over a strong economy and built up a solid support base by investing in healthcare, education and infrastructure.
But the 64-year-old has also polarised opinion, cracking down on opponents and putting some 160,000 people in jail.
Mr Erdogan gave a triumphant victory speech from the balcony of his party's headquarters in the capital Ankara at 03:00 (00:00 GMT), declaring: "The winner of this election is each and every individual among my 81 million citizens."
Congratulations have come in from Islamic leaders including Iranian President Hassan Rouhani. Russian President Vladimir Putin talked of Mr Erdogan's "great political authority and mass support".
Image copyright Getty Images Image caption Supporters of Erdogan and the AK Party took to Istanbul's streets to celebrate
Mr Ince, from the Republican People's Party (CHP), said the election was unfair from its declaration to the announcement of the results.
Turkey was entering a dangerous period of one-man rule, he added.
But he said that there was no significant difference between official results and his party's figures, and therefore he would accept the outcome.
There were another four candidates on the presidential ballot, all of whom fell below 10% of the vote.
What does the result mean?
President Erdogan will assume major new powers under Turkey's new constitution. The changes were endorsed in a tight referendum last year by 51% of voters, and are due to come into force after the election.
They include:
Directly appointing top public officials, including ministers and vice-presidents
The power to intervene in the country's legal system
The power to impose a state of emergency
Some critics argue the enhanced role will place too much power in one person's hands, and that Turkey's new system lacks the checks and balances of other executive presidencies like France or the US.
Mr Erdogan maintains his increased authority will empower him to address Turkey's economic woes and defeat Kurdish rebels in the country's south-east.
In his victory speech, he said Turkey would act more firmly against terrorist groups, and would continue to "liberate Syrian lands" so refugees could return to their homes there.
Mr Erdogan was prime minister for 11 years before becoming president in 2014. Under the new constitution, he could stand for a third term when his second finishes in 2023, meaning he could potentially hold power until 2028.
'Progressive values are still here'
By Mark Lowen, BBC Turkey correspondent
Despite 90% of the media being pro-government and largely shunning the opposition, the president's posters and flags dwarfing any challenge on the streets, the election being held under a state of emergency curtailing protests, and critical journalists and academics being jailed or forced into exile, Mr Erdogan only got half of the country behind him.
"We are living through a fascist regime", the opposition MP Selin Sayek Boke told the BBC. "But fascist regimes don't usually win elections with 53%, they win with 90%. So this shows that progressive values are still here and can rise up."
For now, though, this is Mr Erdogan's time. With his sweeping new powers, scrapping the post of prime minister and able to choose ministers and most senior judges, he becomes Turkey's most powerful leader since its founding father Ataturk.
He'll now hope to lead the country at least until 2023, a hundred years since Ataturk's creation. And a dejected opposition will have to pick itself up and wonder again if, and how, he can be beaten.
Read more from Mark
Who won seats in Turkey's parliament?
Mr Erdogan said the governing alliance led by his AK Party (AKP) had secured a majority, in a separate vote for the 600-member chamber.
State news agency Anadolu said the AKP itself had 42% of the votes for parliament with 99% counted, giving it a projected 293 seats. Its partner, the MHP, had 11% and 50 seats.
The opposition CHP won only 23% (146 seats) despite Mr Ince's popularity in the presidential vote, while its nationalist ally the Iyi (Good) party won 10% (44 seats).
In a development that will please Kurdish voters, the pro-Kurdish HDP exceeded the 10% threshold needed to enter parliament. With 67 seats, it will form the chamber's second-largest opposition faction.
Image copyright AFP Image caption Kurds in Diyarbakir celebrated the HDP's result
The party's success comes despite the fact its presidential candidate Selahattin Demirtas is in a high-security prison on terror charges, which he firmly denies.
Was the voting free and fair?
Security was tight at polling stations. Ahead of the vote, concerns had been raised about potential voter intimidation and electoral fraud.
Voter turnout was high at almost 87%, the state broadcaster reported.
Image copyright AFP Image caption Muharrem Ince has accepted the results, though he believes the poll was unfair
Rights activists have said the press is not free to report on all sides in Turkey. It has become the world's biggest jailer of journalists under Mr Erdogan's rule, according to monitoring groups.
Mr Erdogan has already cautioned his rivals against claiming foul play, saying: "I hope nobody will try to cast a shadow on the results and harm democracy in order to hide their own failure."
What were the election issues?
The biggest was the economy. The Turkish lira has tanked and inflation stands at about 11%, though the economy has grown substantially in recent years.
The currency has suffered as Mr Erdogan has pressed the central bank not to raise interest rates and suggested before the poll that he might restrict its independence.
Terrorism was another key issue, as Turkey faces attacks from Kurdish militants and the jihadists of the Islamic State group.
Mr Erdogan's rivals accused him of damaging civil liberties in Turkey and spearheading a slide into authoritarian rule.
Turkey has been under a state of emergency since a failed coup in July 2016, with 107,000 public servants and soldiers dismissed from their jobs. More than 50,000 people have been imprisoned pending trial since the uprising.
Image copyright Getty Images Image caption Muharrem Ince attracted huge crowds on the campaign trail
CHP candidate Mr Ince's fiery campaigning helped to revitalise Turkey's downtrodden opposition - but ultimately he lacked the numbers to end Mr Erdogan's dominance.
BBC Turkey correspondent Mark Lowen tweeted: "Yet again one half of #Turkey feels invincible, the other distraught."
What term do you want to search? Search with google
Recep Tayyip Erdoğan has addressed thousands of supporters in Ankara after being declared the victor in Turkey’s presidential election, saying democracy was the winner and that Turkey was “an example for the rest of the world”.
“We have received the message that has been given to us in the ballot boxes,” he said, speaking from the balcony of the AK party’s headquarters in Ankara, to a large crowd of cheering and flag-waving supporters. “We will fight even more with the strength you provided us with this election.”
He began by apologising for being late to the balcony speech, saying this was due to the fact that a small child was injured in the crowd in Istanbul, where he had been speaking before, and he went to speak to the child’s family.
Erdoğan spoke of his commitment to “fight terroristic organisations”, “to continue the fight to make the Syrian grounds freer” and to increase the “international prestige” of Turkey, saying: “Turkey has no moment to waste, we know that.”
“Our flag will flutter more freely, the peace of every citizen will be advanced,” he said, before leading the crowd in a chant of “One nation, one flag, one country, one state.”
Earlier on Sunday night, the country’s electoral board said the incumbent had won with 97.7% of votes counted. Even before this declaration, Erdoğan seemed sure of the result.
“Our people have given us the job of carrying out the presidential and executive posts,” Erdoğan said on Sunday night, even while ballots were still being tallied. “I hope nobody will damage democracy by casting a shadow on this election and its results to hide their failure.”
The main opposition party did not immediately concede defeat, but after initially saying Erdoğan would fall well short of a first-round victory, it later said it would continue its democratic struggle “whatever the result”.
Totalitarian tyrant or trusted leader? Turkish voters split on Erdoğan Read more
The official Anadolu Agency reported that, with 99% of votes counted, Erdoğan had won a 52.54% share of the national vote, while the opposition CHP party’s candidate, Muharrem İnce, was on 30.68%.
The pro-Kurdish party, known as the HDP, took 11.67% of the vote, passing the 10% threshold to enter parliament for a second consecutive term. This diluted the majority of Erdoğan’s ruling party, the AKP, but fell short of the numbers needed to overturn that majority after a surprise showing by the AKP’s nationalist allies.
“This sets the stage for speeding up reforms,” the Turkish deputy prime minister, Mehmet Şimşek, tweeted of the results.
The winner of the presidential race is set to assume extraordinary new powers narrowly approved in a referendum last year that was marred by allegations of fraud. These include complete control of the cabinet and the power to appoint senior judges and officials, including unelected vice-presidents. The president will also have the power to issue decrees with the force of law.
Those powers will allow the victor to transform Turkey’s political scene for years and possibly decades to come, governing until 2028 if he wins re-election. Opposition candidates had pledged to overturn the presidential system if they had won.
The results, if they stand, will be a disappointment to the opposition, which had hoped to push Erdoğan into a second-round runoff against İnce, and to wrest control of the legislature from the AKP. Erdoğan and his party have governed unopposed for 16 years.
The president called early the snap elections in April hoping to preempt worsening economic trends and to catch the opposition by surprise. He looked set to win easily in a presidential race and in parliament in alliance with the nationalists, projecting an image of a commander-in-chief fighting external enemies inside Turkey and across the border in Syria, and triumphant against terror groups.
But the opposition mounted a dynamic election campaign, with its presidential candidate İnce drawing crowds in the hundreds of thousands in rallies in the country’s largest cities of Istanbul, İzmir and Ankara, and criss-crossing the country on dozens of rallies.
Turnout at the elections hovered around an extraordinary 87% of the electorate, exceeding that of last year’s referendum.
Opposition officials cried foul as soon as results began coming in, with the state-run Anadolu Agency announcing preliminary results more than two hours earlier than expected and opening with a massive lead for Erdoğan and his party’s alliance in parliament.
That lead closed over time, but it prompted accusations by the opposition that the state news agency was launching a manipulation operation to influence election monitors into leaving ballot counting stations early.
For much of the count, rival vote estimates by the opposition and the state-run agency were published, the former showing Erdoğan winning with less than 50% of the vote, and the latter showing a first-round outright victory.
The first result would lead to a second-round contest on 8 July, a possibility that would represent a major psychological blow for Erdoğan, even if he was tipped to win that contest as well.
The main secular opposition party, İnce’s CHP, continued to contest the results well into the count, charging that less than 40% of ballot boxes had been opened, and that many of İnce’s strong electoral districts had not yet been counted.
İnce urged ballot count monitors to remain at their stations until the counts had been completed to protect against election fraud.
Nevertheless, Erdoğan had already been congratulated on a win in the race by Hungary’s strongman leader, Viktor Orbán.
The election took place on an uneven playing field, against a backdrop of human rights abuses that Amnesty International described as a “climate of fear”.
One of the presidential candidates, Selahattin Demirtaş, ran his presidential campaign from a prison cell in Edirne where he is on trial on terrorism charges. The government has either shuttered, bought or taken over newspapers and TV stations, transforming the vast majority of the nation’s media into a loyalist press.
Thousands of people have been detained or dismissed since a coup attempt in 2016, a crackdown that has gone beyond the followers of Fethullah Gülen, the man accused of masterminding the coup from his exile in Pennsylvania, to dissidents of all stripes including academics, students who opposed military incursions into Syria, judges, bureaucrats and police and military officers.
Nevertheless, there were few incidents of apparent electoral fraud, with the exception of the province of Urfa, where some apparent attempts to rig the vote were uncovered during the course of the day. Poll stations opened at 8am and closed at 5pm.