Turkish Prime Minister Tayyip Erdogan claims victory in local polls that became a referendum on his rule. (Reuters)

The party of embattled Turkish Prime Minister Recep Tayyip Erdogan headed for a comfortable win in municipal elections Sunday, despite a corruption scandal and complaints about his increasingly authoritarian behavior.

With more than 80 percent of the ballots counted, Erdogan’s Justice and Development Party (AKP) was leading with about 44 percent of the vote, well ahead of its nearest rival, the Republican People’s Party (CHP), which had 29 percent.

The result will be seen as a resounding victory for Erdogan and a vindication of his increasingly heavy-handed tactics, including the imposition of bans on the social media sites Twitter and YouTube in the days ahead of the vote, said Soli Ozel, professor of international relations at Kadir Has University.

“The tactics worked,” he said. “It is a big success for Erdogan and a big failure for the opposition.”

Shortly before midnight, Erdogan declared victory to a jubilant crowd in Ankara, delivering a defiant speech in which he taunted his opponents and vowed to hunt down those responsible for disseminating allegations of corruption against him.

“We are going to go into the caves of those traitors,” he said, referring to the Gulenist movement headed by Fethullah Gulen, a charismatic religious leader and former ally whom Erdogan has accused of leaking tapes that appear to reveal widespread corruption within his administration. “Some of them may run away, but they are going to pay for what they have done.”

The closely watched poll took on the significance of a national referendum on Erdogan’s 11-year-old rule after a slew of corruption allegations threatened to tarnish his reputation. The accusations, taking the form of leaked recordings of conversations mostly featuring the prime minister that were anonymously posted online, prompted Erdogan to lash out at social media and crack down on journalists.

Many of those who headed to the polls in central Istanbul, where anti-government demonstrations were ruthlessly suppressed last year, said they feared for democratic freedoms in a Turkey run by the increasingly autocratic prime minister.

“People are voting just to get rid of Erdogan,” said Meltem Safak, 28, who participated in last summer’s demonstrations and cast her ballot for the secular opposition CHP. “We are voting against dictatorship.”

Yet, as Sunday’s result showed, Erdogan can count on the loyalties of a core constituency of Turks, many of them from the working and lower middle class, who share his conservative inclinations and applaud the transformation he has brought to the once-dismal Turkish economy. Maps of the results showed the CHP leading in constituencies in the wealthier, urban and coastal areas, while the AKP was winning in the vast, less affluent hinterland.

“You have to remember what he has done for the country,” said Yasar Ayhan, 48, a barber who used to cut Erdogan’s hair when he served as mayor of Istanbul.

Sunday’s results suggested that the prime minister’s popularity has been only slightly dented by the scandal, setting the stage for him to remain in power in some capacity for the foreseeable future. His party’s share of the vote was lower than the 50 percent landslide he won in general elections in 2011, but it was considerably higher than the 39 percent scored in the last local elections, in 2009.

Crucially, the AKP was set to retain control of Ankara, the capital, and Istanbul, regarded as a bellwether for this summer’s presidential election and for parliamentary elections scheduled for next year.

Erdogan has not disclosed his intentions ahead of those two votes. It was widely assumed that he was waiting for the results of the municipal elections before deciding whether to run for the presidency — a largely symbolic position — or for an unprecedented fourth term as prime minister next year. His party’s rules prohibit him from serving more than three terms, but Sunday’s results may ease the way for him to change the restriction.

The results seem unlikely, however, to ease the bitter divisions that emerged over the fiercely contested poll, which has polarized the country between pro-and anti-Erdogan camps, said Henri Barkey, an international relations professor at Lehigh University.

“Turkey from tomorrow on will be more divided than ever, with each side seeing the other as illegitimate,” he said. “It’s unprecedented.”