ISTANBUL — Turkey's main opposition claimed a decisive victory on Sunday in Istanbul's re-run election, dealing one of the biggest blows to President Tayyip Erdogan during his 16 years in power and promising a new beginning in the country's largest city.

Ekrem Imamoglu, mayoral candidate of the secularist Republican People's Party, was leading with 54 percent of votes against 45 percent for Erdogan's AK Party candidate, with more than 99% of ballots opened, Turkish broadcasters said.

The election was Istanbul's second in three months after results of an initial March vote were scrapped, setting up the do-over as a test of Turks' ability to check what many saw as their president's increasingly authoritarian power.

"Today, 16 million Istanbul residents have renewed our faith in democracy and refreshed our trust in justice," Imamoglu told supporters.

His AK Party opponent, former Prime Minister Binali Yildirim, congratulated him and wished him "all the luck" in serving Istanbul, Turkey's commercial hub. Erdogan also tweeted his congratulations to the Republican People's Party candidate.

Imamoglu had won the original mayoral election on March 31 by a narrow margin, which prompted the Islamist-rooted AK Party to demand a re-run, citing what it said were voting irregularities.

The High Election Board's decision to grant that request drew sharp criticism from Turkey's Western allies and from Erdogan's opponents at home, stirring concerns about the rule of law and raising the stakes for the re-run.

Broadcasters put the Republican People's Party lead on Sunday at about 800,000 votes, eclipsing the roughly 13,000-vote margin in March.

The election board said it would announce the election results as soon as possible.

"While March 31 was a mayoral election, this re-run was one to put an end to the dictatorship," said Gulcan Demirkaya, 48, from the city's AK Party-leaning Kagithane district.

"God willing, I would like to see (Imamoglu) as the president in five years' time," she said. "The one-man rule should come to an end. For the first time in a long time, I am very happy and proud for my country."

Imamoglu, a former businessman and district mayor who waged an inclusive campaign and avoided criticizing Erdogan, said he was ready to work with the AK Party to tackle Istanbul's problems, including its transport gridlock and the needs of its Syrian refugees.

"In this new page in Istanbul, there will from now on be justice, equality, love, tolerance; while misspending (of public funds), pomp, arrogance and the alienation of the other will end," he said.

Erdogan himself served as Istanbul's mayor in the 1990s before he embarked on a national political career, dominating Turkish politics first as prime minister, then as president. He presided over years of strong economic growth. But critics say he has become increasingly autocratic and intolerant of dissent.

The second defeat in Istanbul marked a major embarrassment for the president and could also weaken what until recently seemed to be his iron grip on power. He had campaigned hard and targeted Imamoglu directly with accusations of lying and cheating.

"This is definitely going to have an impact on the future of Turkish politics given the margin of victory. It's an alarming sign for the AKP establishment," said Sinan Ulgen, visiting scholar at Carnegie Europe in Brussels and a former Turkish diplomat.

Analysts say the loss could set off a Cabinet reshuffle in Ankara and adjustments to foreign policy. It could even trigger a national election earlier than 2023 as scheduled, although the leader of the AK Party's nationalist ally played down that prospect.

"Turkey should now return to its real agenda, the election process should close," Republican People's Party leader Devlet Bahceli said. "Talking of an early election would be among the worst things that can be done to our country."

Turkey's economy is in recession and the United States, its NATO ally, has threatened sanctions if Erdogan goes ahead with plans to install Russian missile defenses.