ISTANBUL (AP) — Turkish President Recep Tayyip Erdogan declared victory in municipal elections but the opposition’s success in key cities dealt a significant blow to his party’s dominance. The ruling party lost the capital, Ankara, and the race for Istanbul mayor was still too close to call early Monday.

Sunday’s local elections were widely seen as a test of support for Erdogan as the nation of 81 million people faces a daunting economic recession with double-digit inflation, rising food prices and high unemployment.

The main opposition party winning the race for metropolitan mayor in Ankara marks a symbolic shift. The capital city was held by Erdogan’s Justice and Development Party, the AKP, and its Islamic-oriented predecessor for 25 years.

More than 57 million voters were eligible to take part in choosing the mayors of 30 major cities, 51 provincial capitals and 922 districts in Turkey. In big cities, voters cast four ballots, for metropolitan mayor, district mayor, the municipal assembly and a neighborhood administrator.

According to unofficial results reported by the state-run Anadolu news agency, Mansur Yavas, the candidate of the secular Republican People’s Party, or CHP, won the top post in Ankara. The AKP still holds a majority of Ankara’s 25 districts.

The government had led a hostile campaign against Yavas and his party, accusing him of forgery and tax evasion.

But Erdogan still came out on top as the ruling party and an allied nationalist party won more than half of the votes across Turkey.

Speaking from the balcony of party headquarters in Ankara early Monday, where he has for years declared victory, Erdogan said he and his allies had come out first. Admitting setbacks, he said the party would work to understand and fix where they failed.

Ballot counts were still underway Monday morning in Turkey’s largest city and commercial hub, Istanbul. Both candidates —Ekrem Imamoglu for the CHP and former Prime Minister Binali Yildirim for the AKP— claimed they had won.

The opposition accused Anadolu of bias, and the agency’s unofficial results for Istanbul were stuck at 98 percent of votes counted for hours. The private Demiroren news agency showed Imamoglu leading Monday.

The mayor’s seat in the city of 15 million is important. Erdogan’s own ascent to power began there in 1994.

In predominantly Kurdish provinces, a pro-Kurdish party won seven top mayoral seats but lost some strongholds, including southeastern Sirnak province, to the ruling party.

Since 2016, the government has replaced 95 elected municipal, provincial or district mayors with government-appointed trustees in a crackdown on the Peoples’ Democratic Party, or HDP, for alleged links to outlawed Kurdish militants.

The HDP had vowed to win them back. Amid a media blackout and despite significant losses in the region, it regained the municipal mayor in the Kurds’ symbolic capital, Diyarbakir. Government officials have previously threatened they won’t recognize results if HDP candidates with “terror” links win.

The secular opposition also made significant gains in provinces along the Mediterranean, including taking Adana from the nationalists and the resort-town of Antalya from the ruling party. It also retained its hold over Izmir, Turkey’s third largest city, located on the Aegean Sea. If Imamoglu wins in Istanbul, the opposition will administer the three most populous cities.

A strategic decision by the pro-Kurdish party to sit out critical races in major cities may have contributed to the secular party’s increase in votes.

Turkey will also have its first communist mayor, in the eastern province of Tunceli.