(CNN) — President Recep Tayyip Erdogan has won Turkey’s presidential election, defeating opposition leader Kemal Kilicdaroglu in Sunday’s runoff vote and stretching his rule into a third decade.

With 99.43% of the votes counted, preliminary official results announced by Turkey’s Supreme Election Council (YSK) showed Erdogan winning with 52.14% of the votes. Kilicdaroglu received 47.86%.

Before the results were made official, Erdogan appeared to take a victory lap outside his residence in Istanbul, singing in celebration on top of a campaign bus. Addressing a large crowd of jubilant supporters waving the Turkish flag, he thanked the nation.

“We completed the second round of the presidential election with the favor of our nation. I would like to express my gratitude to my nation for giving us a day of democracy,” Erdogan said.

“The winners of both the 14 May elections and the 28 May elections are all our 85 million citizens,” he added, referring to the two election rounds.

Speaking at his party headquarters in the capital Ankara, Kilicdaroglu said he would continue to fight until there is “real democracy” in Turkey.

“This was the most unfair election period in our history… We did not bow down to the climate of fear,” he said. “In this election, the will of the people to change an authoritarian government became clear despite all the pressures.”

Kilicdaroglu said what “truly makes me sad is the hard days ahead for our country.”

Foreign leaders including those of Russia, Qatar, Libya, Algeria, Hungary, Iran and the Palestinian Authority were among the first to congratulate Erdogan.

Erdogan’s supporters gathered In Istanbul’s Taksim Square, chanting his name and “God is great.”

Hundreds of people gathered outside the Istanbul headquarters of the ruling Justice and Development (AK) Party after preliminary results showed Erdogan in the lead. Some came with children while others waved flags, honked car horns and set off flares and fireworks.

Mehmet Karli, adviser to Kilicdaroglu, called Erdogan’s election win a “pyrrhic victory” accusing the president of fueling tensions during the election.

“It does appear that President Erdogan has won these elections. But it would be a mistake to call this a victory. Perhaps a Pyrrhic victory is a better term to describe this situation,” Karli said.

Erdogan’s victory over Kilicdaroglu, a 74-year-old bureaucrat and leader of the left-leaning CHP, leaves Turkey a deeply divided nation.

“This is not a crushing defeat for those who wanted change,” Asli Aydintasbas, a visiting fellow at Brookings Institution, told CNN’s Becky Anderson. “We are once again looking at a divided country … both camps want entirely different things for Turkey.”

In the first round of voting on May 14, Erdogan secured a nearly five-point lead over Kilicdaroglu but fell short of the 50% threshold needed to win. 

The president’s parliamentary bloc won a majority of seats in the parliamentary race on the same day. 

Electoral authorities said earlier that voting was passing “without any issues.”

Last week, third-place candidate Sinan Ogan, who won 5% of the first-round vote, publicly endorsed Erdogan, further boosting the strongman leader’s chances of winning Sunday’s second and final presidential round. 

Many polls had incorrectly predicted that Kilicdaroglu would lead in the May 14 vote, which saw a high turnout of nearly 90% across the country. 

Six opposition groups had formed an unprecedented unified bloc behind Kilicdaroglu to try to wrest power from Erdogan.

The opposition has described the election as a last stand for Turkish democracy, accusing Erdogan of hollowing out the country’s democratic institutions during his 20-year rule, eroding the power of the judiciary and repressing dissent.

Erdogan also faces headwinds from a floundering economy and a shambolic initial response to a catastrophic earthquake on February 6 which claimed more than 50,000 lives in Turkey and neighboring Syria.

The government acknowledged its “mistakes” in its rescue operation and apologized to the public. 

Erdogan’s critics also spotlighted loose construction standards presided over by the ruling AK party, which turbocharged a construction boom since the early 2000s, and exacerbated the death toll. They also argued that the earthquake response underscored Erdogan’s alleged hollowing out of government entities in his bid to consolidate power. 

The country’s financial crisis — which saw the currency plummet and prices soar — is also partially blamed on Erdogan’s policies. The president suppressed interest rates leaving inflation unfettered, critics argued.  

In an interview with CNN’s Becky Anderson last week, Erdogan vowed to double down on his unorthodox economic policies, arguing that interest rates and inflation were “positively correlated.”

He also hailed his relationship with Russian President Vladimir Putin as “special” and said he would continue to block Sweden’s access to NATO, despite Western criticism that he was obstructing a unified front against Russia’s invasion of Ukraine. 

Erdogan, who controls the second-largest army in NATO, accused Sweden of harboring Kurdish terror groups and has preconditioned Stockholm’s accession on the extradition of wanted individuals. Sweden has refused Turkey’s repeated requests to extradite individuals Ankara describes as terrorists, arguing that the issue can only be decided by Swedish courts.

Sweden’s Prime Minister Ulf Kristersson congratulated Erdogan for his victory. “Our common security is a future priority,” he tweeted.

Since Russia launched its invasion of Ukraine in February 2022, the Turkish strongman has emerged as a key powerbroker, adopting a crucial balancing act between the two sides, widely known as “pro-Ukrainian neutrality.”

He helped broker a key agreement known as the Black Sea Grain Corridor Initiative that unlocked millions of tons of wheat caught up in Russia’s invasion of Ukraine, averting a global hunger crisis. The agreement was extended for another two months last Wednesday, one day before it was set to expire.

The-CNN-Wire™ & © 2024 Cable News Network, Inc., a Time Warner Company. All rights reserved.

Join our Newsletter for the latest news right to your inbox