ISTANBUL — In an emotional post-election speech late Sunday night, Recep Tayyip Erdogan, Turkey's embattled prime minister, made one thing clear: He isn't going anywhere.

He suggested instead that he'll veer more hardline in fighting off the mounting challenges to his 11-year run in office, vowing to pursue arrests against his rivals and even predicting that some might flee.

Despite months of alleged phone-tap leaks that paint Erdogan and his allies as shockingly corrupt — and the outcry over his recent bans of YouTube and Twitter — his Islamic-rooted Justice and Development Party (AKP) won a resounding victory in municipal elections held across the country on Sunday. It took some 45% of the vote, nearly 20% more than its nearest competitor, and kept its crucial hold on Istanbul and Ankara.

Both Erdogan and his opponents had painted the polls as a referendum on his standing amid the crisis. He called the result an "Ottoman slap" for his enemies — and seemed to be planning more. "They will pay the price," he said.

Erdogan has won praise at home and abroad for elevating Turkey's middle class and pushing its military out of politics. But he has faced unprecedented resistance since June 2013, when protests over the demolition of an Istanbul park spiraled into nationwide unrest over his heavy-handed governing style. Erdogan refused to back down then and has stuck to that posture amid the scandal rocking his government now — sending riot cops to quell protests and purging hundreds of police and justice officials to combat ongoing corruption probes.

Throughout, he has stressed repeatedly that there's only one way to beat him — at the ballot box.

But Erdogan's increasing crackdowns are sparking concern that even elections in Turkey may be turning into an unfair fight. As two important national votes approach, Erdogan appears more willing than ever to bend the country's democratic institutions to his will — or even to subvert them — in order to keep his hold on power.

"I think he'll use whatever means possible," said Steven A. Cook, a senior fellow at the Council on Foreign Relations. "There's a sense that there are no rules any more. It's all about the preservation of Erdogan and the AKP."

Turkey will hold presidential elections in August, while parliamentary polls are due next year and could be called sooner. A newly emboldened Erdogan is expected to compete in one of these votes. AKP bylaws on term limits technically rule out another run for the three-time prime minister, but they could be rewritten, allowing him to stand again. Or he may run for president, a largely ceremonial post now that would be sure to grow in influence in Erdogan's hands.

With these votes on the horizon, Cook and other observers said, Erdogan and the AKP will likely work to consolidate power — and to ensure that they retain the upper hand against any potential challenge at the polls. "I think they'll use every tool they have," Cook said. "They'll use a combination of things like coercion, intimidation, and using the institutions of the state that they can manipulate to get what they want."

Erdogan and the AKP already exert considerable influence over the country's press, using financial intimidation of media companies to win favorable coverage and sometimes suing journalists who draw their ire. In one recent leak, Erdogan calls the director of a major TV station to get an opposition politician's speech pulled off the air; in another he reduces a powerful newspaper owner to tears. These intimidation tactics have lately expanded to the outlets publishing news of the leaks — one editor was questioned by police last week, and several opposition news sites were knocked offline by cyber attacks on election day.

In addition to its recent social media bans, the government has given itself powerful new web censorship tools. If it begins to arrest those it blames for the corruption leaks, as Erdogan has suggested, it will raise the stakes considerably. Cook said the AKP could also pass laws to increase its control over the electoral process — much as recent legislation has tightened its control over the judiciary. An ineffectual opposition that even many Erdogan critics despise enables such efforts. "It's a system where there are really no checks and balances any longer," Cook said. "The question is what kind of resistance they'll get."

The situation looks ripe for escalation from both sides, said Soner Cagaptay, the director of the Turkish Research Program at the Washington Institute. For the first time in the upcoming polls, he said, Erdogan may see groups from across Turkey's fragmented political spectrum band together to challenge him. "It's not that they agree politically," he said. "But they agree on one thing: An elected government cannot be authoritarian."

Erdogan seems less likely than ever to back down. He is embroiled in a bitter feud with a powerful one-time ally, the Islamic cleric Fetullah Gulen, who is thought to command considerable influence in Turkey from his self-exile in Pennsylvania, particularly over the police and judiciary. Gulen and his followers are widely believed to be driving the recent corruption investigations and leaks. Erdogan has called them a "parallel state," and it's Gulenists in Turkey that he likely plans to target with arrest.

At the same time, Erdogan remains locked in an increasingly divisive struggle with Turkey's political opposition — and in particular the largely young and left-leaning segment of the population who filled the streets for last year's demonstrations and have been especially riled by the social media bans.

Erdogan may feel that he must retain power to prevail in these battles, Cagaptay said — and to keep the immunity of the prime minister's office to avoid facing charges in the corruption probes. "He has created so many political enemies, and so polarized the landscape, that he cannot afford to lose," Cagaptay said. "It's very likely that he will become even more authoritarian to prevent the opposition from taking control."

In the coming months, these power struggles could reach a head in the battle for web freedom in Turkey, Cagaptay added. "It's where all these other freedoms collide," he said. "Freedom of assembly, expression, and media are all embodied now in freedom of the internet."

As the polls closed on Sunday night, for the first time in recent memory, many Turks sounded the alarm about potential voter fraud. But there was no evidence to support these claims — and in this round of voting at least, Erdogan and the AKP didn't need the help. As Michael A. Reynolds, a Princeton University professor who has studied Turkish elections, put it: "Erdogan has definitely been shaken. But he's still in place."

The recent corruption allegations have "landed with a muffled thud" among much of the electorate, he added. "There's no sign that they have really damaged Erdogan."

Henri Barkey, a Turkey specialist at Lehigh University, noted that Erdogan's voters have so far stuck with him. "People are voting for him not because they're blind, but because they're better off than they were 10 years ago," he said. "That's a very strong argument."

Yet many financial analysts have warned that Turkey's economy is weakening — and it has been shaken by the last year of unrest.

Erdogan's strategy to combat the recent challenges has been to go on the attack — demonizing his opponents and seeming to savor the country's growing polarization in order to mobilize his base. "I have never seen anything like this [in Turkey]," Barkey said. "The society has become evenly divided — and each side sees the other as illegitimate. And that bodes very poorly."

Kerem Oktem, a scholar at Oxford University who writes on modern Turkey, said that even Erdogan's victory at the polls on Sunday saw him take less than half of the vote — leaving much of the country increasingly at odds with him as he tightens his grip. "I can't envision how the 55% of Turks who are not pro-Erdogan are going to consent to this transfer to dictatorship," he said.

As for Erdogan, Oktem added: "He will fight until the bitter end."