A tense political situation may be brewing in Turkey after the opposition candidate for mayor of Istanbul won Sunday, breaking the long hold President Recep Tayyip Erdogan’s party had on leading Turkey’s largest city.

“Thank you, Istanbul,” Ekrem Imamoglu, 49, said to the tens of thousands of people who gathered to mark his victory after unofficial results showed he won a clear majority of the vote in a closely watched repeat election that ended weeks of political tension.

The governing party’s candidate, former Turkish Prime Minister Binali Yildirim, conceded moments after returns showed him trailing well behind Imamoglu, 54 percent to 45 percent.

“Thank you, Istanbul,” Ekrem Imamoglu, 49, said to the tens of thousands of people who gathered to mark his victory after unofficial results showed he won a clear majority of the vote. (AP Photo/Lefteris Pitarakis)

Imamoglu increased his lead from a March mayoral election by hundreds of thousands of votes.

PETE BUTTIGIEG NOW REGRETS SAYING 'ALL LIVES MATTER'

Analysts noted the president, who is grappling with an economic downturn and several international crises, could limit the mayor’s power or undermine Imamoglu’s authority in other ways.

Lisel Hintz, an assistant international relations professor at Johns Hopkins University SAIS, said Imamoglu withstood a divisive campaign and prevailed with a positive message.

The significance of his win “cannot be understated,” Hintz said.

“We now have to wait and see whether Imamoglu’s tenure as mayor will be interfered with in any way, whether by cutting off funding and hampering his office’s ability to provide services or by removing him under some legal pretext,” Hintz said.

Erdogan has previously signaled an unwillingness to work with an opposition mayor, saying his party controlled 25 of Istanbul’s 39 districts and a majority in the municipal assembly. Imamoglu would have to work with those officeholders to govern Istanbul, and he promised to do so Sunday.

Addressing Erdogan in a speech, Imamoglu said, “I’m ready to work with you” to solve Istanbul’s problems.

Turkey's President Recep Tayyip Erdogan casting his ballot Sunday. (AP Photo/Emrah Gurel)

Ozgur Unluhisarcikli, Ankara office director of the German Marshall Fund, argued that the loss of Istanbul likely would fuel speculation of divisions within the ruling party and among its supporters.

“It’s now clear that a sizable portion of the AKP voters is seriously dissatisfied by policies of the AKP,” he said. “The (opposition) was a house that was united. The AKP house looked like one that was already divided.”

He argued Erdogan already was facing an “a perfect storm” this summer. Erdogan has been at odds with Western allies over Turkey’s plans to buy the Russian-made S-400 missile defense system and its challenge of EU-member Cyprus over natural gas drilling rights.

Imamoglu narrowly won an earlier mayoral election on March 31, but Erdogan’s Justice and Development Party, AKP, challenged the vote over alleged irregularities. He spent 18 days in office before Turkey’s electoral board annulled the results after weeks of partial recounts.

The voided vote raised concerns domestically and abroad about the state of Turkish democracy and whether Erdogan’s party would accept any electoral loss. AKP has governed Turkey since 2002.

“You have protected the reputation of democracy in Turkey with the whole world watching,” Imamoglu, his voice hoarse after weeks of campaigning, told supporters.

Jubilant supporters chanted “Mayor again! Mayor again!” Others hung out of cars, blaring horns and waving red-and-white Turkish flags.

Erdogan campaigned hard for Yildirim in Istanbul, Turkey’s commercial and cultural hub, where the president started his political career as mayor in 1994.

Istanbul, a city of more than 15 million, has drawn millions of tourists each year. Straddling Europe and Asia, Istanbul accounted for 31 percent of Turkey’s GDP in 2017.

AKP also lost control of the capital city of Ankara in Turkey’s March local elections, which were held as the country battled high inflation and two credit rating downgrades in the past year.

CLICK HERE TO GET THE FOX NEWS APP

Melahat Ugen said she switched her vote to the opposition because she could not afford to cover basic expenses.

“I’ve certainly never voted left before,” she said. “But, I’m 62, and a bag of onions costs too much. Everything is imported and we can’t afford it.”

The Associated Press contributed to this report.