Turkey's prime minister has declared victory in local elections that had become a referendum on his rule, calling the results a blow to the "immoral, aimless politics" of his rivals.

Recep Tayyip Erdogan warned his rivals would "pay the price" for their loss as preliminary results on Sunday showed his Justice and Development party, known as the AKP, took up to 47 percent of all votes cast.

The main opposition Republican People's Party, known as the CHP, had 28 percent and the Nationalist Movement Party, or Erdogan, had 13 percent, the Anatolia news agency reported late on Sunday.

The elections, which were being held amid corruption allegations and damaging security leaks that have shaken the 12-year rule of the AKP government, were widely seen as a vote of confidence for the rule of Erdogan.

At a rally in Ankara in the early hours of Monday, Erdogan said that "democracy and free will" had won.

"These poll results show more than who won, it shows who lost," he said. "Immoral politics have lost. Politics on tapes, on false recordings have lost. Immoral and aimless politics have lost."

He took aim at rivals who sought to capitalise on the leaked recording, posted on YouTube, in their campaign against him, and the press.

"I ask the leader of the opposition if he didn't have the recordings, what would you have said on your campaign? You only utter lies and false statements."

He gave warning that his foes would "pay the price". "From tomorrow, there may be some who flee," he said.

Hectic campaigning

More than 50 million voters were eligible to cast their ballots in Turkey's local elections.

The AKP, which swept to power in 2002 on a platform of eradicating the corruption that blights Turkish life, hoped on Sunday to equal or better its overall 2009 vote of 38.8 percent.

Erdogan crisscrossed the nation of 77 million during weeks of hectic campaigning to rally his conservative core voters, during which he temporarily lost his voice.

His government has purged thousands of people from the judiciary and police since December following the anti-corruption raids targeting businessmen close to Erdogan and sons of ministers.

The prime minister said that those behind the investigations were trying to form a "state within a state" or "parallel state", blaming the movement of Fethullah Gulen, the US-based Turkish cleric whose followers are apparently highly influential in Turkey's police forces and judiciary.

Many analysts say that the two sides used to be allies in the past in their struggle against Turkey's politically dominant military.

The CHP portrayed Erdogan as a corrupt "dictator" ready to hang on to power by any means. Capture of the capital Ankara or Istanbul would allow them to claim some form of victory, although no result has been declared in either city.