Prime Minister Recep Tayyip Erdogan has claimed victory for his Islamic-based party in key regional elections and warned his foes they would "pay the price" for plotting his downfall.
"Those who attacked Turkey got disappointed," Erdogan told a jubilant crowd of thousands, speaking on Sunday from the balcony of his party's Ankara headquarters after months of turmoil marked by street clashes, sleaze claims and an internet clampdown.
"You have supported your prime minister. I thank you infinitely," Erdogan told the crowd, his voice still hoarse from marathon campaigning for the municipal polls that were seen as a referendum on his 11-year rule.
Erdogan, 60, has been eyeing a run for the presidency in August, the first time voters will directly elect the head of state. His midnight victory speech sounded at times like the start of his next campaign.
"You have protected the independence struggle of the new Turkey," the man often called "the sultan" told his flag-waving followers, interrupted by chants of "Turkey is proud of you", "Stand tall, don't bow" and "God is great".
With about 98 per cent of votes counted by early yesterday morning, Erdogan's Justice and Development Party (AKP) , in power since 2002, had 45.6 per cent of the vote and the opposition Republican People's Party (CHP) trailing with 28 per cent, according to Turkish television.
The AKP looked headed for strong victories nationwide over the secular opposition, including in the biggest city Istanbul and the capital Ankara.
But in Ankara the main opposition, the centre-left CHP, said the vote was close.
Erdogan again threatened to pursue his declared nemesis Fethullah Gulen, 73, a reclusive Muslim cleric whom he accuses of running a parallel "deep state" undermining his government from rural Pennsylvania in the United States.
Erdogan has accused loyalists of the imam in the police and justice systems of damaging leaks on Twitter and of bugging talks on Syria and then releasing the explosive audio recording on YouTube.
"We will enter their caves and ... they will pay the price," he warned. "How can you threaten our national security on Syria? Syria is currently in a state of war against us. There won't be a state within a state."
Months of political turmoil, fought out in street clashes and the internet leaks, have left Turkey polarised between Erdogan's Muslim conservative supporters and a secular political camp.
Erdogan's inner circle has been hit by the damaging leaks since December, with wide-ranging bribery and sleaze claims against the prime minister and his allies going viral.
Additional reporting by Reuters