Turkey's President Recep Tayyip Erdogan casts his ballot at a polling station in Istanbul, Sunday, June 23, 2019. Polls have opened in a repeat election in Turkey's largest city where Erdogan and his political allies could lose control of Istanbul's administration for the first time in 25 years. (AP Photo/Emrah Gurel)

ISTANBUL (AP) — Turkish President Recep Tayyip Erdogan hasn't lost many elections since the conservative party he co-founded took control of the government in 2002. But the party's rare defeat in Istanbul, Turkey's largest city, was a political and personal setback for the country's leader.

Opposition candidate Ekrem Imamoglu's win Sunday in a repeat vote for mayor broke the lock the president's Islamist-rooted party long held on Istanbul's top public office. On Monday, Turks speculated whether Erdogan's opponents finally have the ability to challenge his rule.

Imamoglu's supporters partied long into the night after he trounced Erdogan's hand-picked candidate, a former prime minister, 54% to 45% in a rerun of the city's March 31 mayoral election. The Islamic-leaning ruling party challenged the first vote over alleged irregularities, and Turkey's electoral board nullified the results.

The streets of Istanbul, where Erdogan's rise in Turkish politics started with his own election as mayor 25 years ago, became an impromptu caravan of cars honking horns with overjoyed passengers leaning out the windows as they cheered and waved Turkish flags.

Imamoglu's victory "is the most serious setback for Erdogan since his Justice and Development Party first took office in November 2002 and will further fuel the already growing sense amongst both his opponents and many members of his own party that his career is now in irreversible decline," Wolf Piccoli of the New York-based risk analysis firm Teneo Intelligence, said.

The landslide win electrified the secular party that has been spent nearly two decades in lackluster opposition as Erdogan's strengthened his hold on power.

The vote count was officially ratified Monday. But Justice and Development Party candidate Binali Yildirim conceded within minutes after the first returns were announced. Tens of thousands of opposition supporters flocked to a square in an Istanbul suburb late Sunday to greet Imamoglu, chanting his campaign slogan, "Everything will be great!"

Erdogan's 1994 election as Istanbul's mayor shocked Turkey's secular elite. A poem he recited during his tenure resulted in a conviction for inciting religious hatred for which he served fours month in prison in 1999. He rose to national prominence a few years later following a financial crisis that wiped out much of the Turkish political establishment.

As president, he has presided over years of growth. However, Turkey's economy has been in-and-out of recession in the last year, and the country is burdened by high borrowing costs and sovereign downgrades.

Turkey's borrowing rates eased Monday after months of political uncertainty. The yield on its 10-year government bond eased to 15.3% after touching 20% in mid-May.

Can Selcuki, general manager of Istanbul Economy Research, a market research and data analytics company, thinks the recent downturn and election result in Istanbul are likely to increase pressure on Erdogan within his own party. Senior officials have publicly distanced themselves and are widely rumored to be setting up two breakaway parties.

"I suspect that the result will speed those (preparations) up," Selcuki said. "If new parties are going to be formed by former AK Party leaders, they might actually grab some (lawmakers). The number they attract to their side is important because that could change the arithmetic in parliament."

The repeat election angered AKP dissenters but also heightened public anxiety over the president's style of leadership, which critics describe as increasingly authoritarian.

Istanbul pastry chef Banu Kirmizigul said she voted in the repeat election, after sitting out the one in March, because she was inspired by Imamoglu's campaign.

"I am really happy and my faith in this country has been restored," she said. "I saw that our people had awakened and I decided to wake up now, and I cast my vote. We (the opposition) got 800,000 more votes. We were successful and I am very happy."

A group of election monitors from the Council of Europe, a Strasbourg-France based organization aimed at holding member states accountable for human rights commitments, said Sunday's election was held "competently and in compliance with the applicable rules."

___

Ayse Wieting, Mehmet Guzel, and Bulut Emiroglu in Istanbul contributed to this report.

___

Follow Derek Gatopoulos at http://www.twitter.com/dgatopoulos and Bilginsoy http://twitter.com/zbilginsoy

Ekrem Imamoglu, candidate of the secular opposition Republican People's Party, or CHP thanks his supporters outside a polling station in Istanbul, Sunday, June 23, 2019. Voters in Istanbul returned to the polls Sunday for a re-run mayoral election ordered up by authorities after President Recep Tayyip Erdogan and his political allies lost control of Turkey's largest city for the first time in 25 years. (AP Photo/Burhan Ozbilici)
Supporters of Ekrem Imamoglu, the candidate of the secular opposition Republican People's Party, CHP, celebrate in central Istanbul, Sunday, June 23, 2019. In a blow to Turkish President Recep Tayyip Erdogan, Imamoglu declared victory in the Istanbul mayor's race for a second time Sunday after Binali Yildirim, the government-backed candidate conceded defeat in a high-stakes repeat election. (AP Photo/Lefteris Pitarakis)
Ekrem Imamoglu, the candidate of the secular opposition Republican People's Party, CHP, waves to supporters at a celebratory rally in Istanbul, late Sunday, June 23, 2019. Tens of thousands of people attended an election night celebration after a repeated vote in Istanbul made Imamoglu the mayor-elect of Turkey's largest city. (Onur Gunay/Imamoglu Media team via AP)
A supporter of Ekrem Imamoglu, the candidate of Turkey's secular opposition Republican People's Party, CHP, holds a poster with modern Turkey's founder Mustafa Kemal Ataturk as she celebrates in central Istanbul, late Sunday, June 23, 2019. The opposition candidate for mayor of Istanbul celebrated a landmark win Sunday in a closely watched repeat election that ended weeks of political tension and broke the long hold President Recep Tayyip Erdogan's party had on leading Turkey's largest city. (AP Photo/Burhan Ozbilici)
Supporters of Ekrem Imamoglu, the candidate of the secular opposition Republican People's Party, CHP, celebrate in central Istanbul, Sunday, June 23, 2019. In a blow to Turkish President Recep Tayyip Erdogan, Imamoglu declared victory in the Istanbul mayor's race for a second time Sunday after Binali Yildirim, the government-backed candidate conceded defeat in a high-stakes repeat election. (AP Photo/Lefteris Pitarakis)
Supporters of Ekrem Imamoglu, the candidate of Turkey's secular opposition Republican People's Party, CHP, celebrate in central Istanbul, late Sunday, June 23, 2019. The opposition candidate for mayor of Istanbul celebrated a landmark win Sunday in a closely watched repeat election that ended weeks of political tension and broke the long hold President Recep Tayyip Erdogan's party had on leading Turkey's largest city. (AP Photo/Burhan Ozbilici)
Andrew Dawson, centre, Head of the Delegation of the Congress of Local and Regional Authorities, Council of Europe, talks during a media conference in Istanbul, Monday, June 24, 2019. The head of the monitoring mission presented preliminary findings a day after the delegation observed the repeat race for Istanbul mayor. Ekrem Imamoglu, the opposition candidate, celebrated a landmark win Sunday in a closely watched election that ended weeks of political tension and broke the long hold President Recep Tayyip Erdogan's party had on leading Turkey's largest city. (AP Photo/Lefteris Pitarakis)
Turkey's President Recep Tayyip Erdogan casts his ballot at a polling station in Istanbul, Sunday, June 23, 2019. Polls have opened in a repeat election in Turkey's largest city where Erdogan and his political allies could lose control of Istanbul's administration for the first time in 25 years. (AP Photo/Emrah Gurel)
Supporters of Ekrem Imamoglu, the candidate of the secular opposition Republican People's Party, CHP, cheer at a celebratory rally in Istanbul, late Sunday, June 23, 2019. Tens of thousands of people attended an election night celebration after a repeated vote in Istanbul made Imamoglu the mayor-elect of Turkey's largest city. (AP Photo)
Supporters of Ekrem Imamoglu, the candidate of the secular opposition Republican People's Party, CHP, celebrate in central Istanbul, Sunday, June 23, 2019. In a blow to Turkish President Recep Tayyip Erdogan, Imamoglu declared victory in the Istanbul mayor's race for a second time Sunday after Binali Yildirim, the government-backed candidate conceded defeat in a high-stakes repeat election. (AP Photo/Lefteris Pitarakis)
Ekrem Imamoglu, candidate of Turkey's secular opposition Republican People's Party, makes a statement after his election victory, in Istanbul, Sunday, June 23, 2019. Turkish President Recep Tayyip Erdogan has congratulated Imamoglu who won a repeat mayoral election in Istanbul and defeated Erdogan's candidate for the second time. (AP Photo/Burhan Ozbilici)