Updated

Turkish President Recep Tayyip Erdogan’s ruling party led Sunday’s mayoral elections but suffered setbacks as the opposition regained hold of the capital Ankara and made significant inroads in other parts of Turkey. The elections, which the Turkish strongman had depicted as a fight for the country’s survival, were largely seen as a test of his support amid a sharp economic downturn.

Erdogan’s conservative, Islamic-based Justice and Development Party, or AKP, took nearly 45 percent of the votes in the elections after 90 percent of the more than 194,000 ballot boxes were counted, according to state broadcaster TRT. The secular, main opposition party, the Republican People’s Party, or CHP had 30 percent.

The CHP’s mayoral candidate for Ankara, Mansur Yavas, however, won control of Ankara after 25 years of rule by the AKP and a predecessor party. The 63-year-old lawyer received more than 50 percent of the votes, according to TRT. The CHP and its allies also posted gains elsewhere, increasing the number of city mayoral seats from 14 in the previous local elections in 2014 to 20, according to the preliminary results.

“History is being written in Ankara,” said deputy CHP leader Haluk Koc, while thousands of supporters celebrated outside the party’s headquarters in Ankara.

Former Prime Minister Binali Yildirim, the ruling party’s candidate for mayor of Istanbul declared victory even though the race in Turkey’s largest city and commercial hub was too close to call. Yildirim garnered 48.71 percent of the votes against the opposition candidate Ekrem Imamoglu’s 48.65 percent, according to TRT.

CHP leader Kemal Kilicdaroglu rebuked Yildirim for declaring victory in Istanbul “in haste” and claimed his party had now control of Turkey three largest city: Istanbul, Ankara and Izmir.

Erdogan attaches great importance to Istanbul where he began his rise to power as its mayor in 1994. He has said at campaign rallies that “whoever wins Istanbul, wins Turkey.” He refrained from declaring victory in the city of 15 million people.

Ankara was considered the main battleground of the race, where a former government environment minister, Mehmet Ozhaseki, ran for mayor under the banner of Erdogan and his nationalist allies. The ruling party accused his opponent Yavas of forgery and tax evasion. Yavas said he is the victim of a smear campaign.

“Ozhaseki and his dirty politics have lost,” Yavas said in a victory speech.

Sunday’s elections were a first test for Erdogan since he won re-election under a new system of government that gave the presidency expanded powers. Erdogan campaigned tirelessly for AKP’s candidates, framing the municipal elections as a matter of “national survival.” He also portrayed the country’s economic woes as attacks by enemies at home and abroad.

“Those who have tried to bring our country on its knees by damaging our people’s unity and togetherness, have once again been dealt a blow,” Erdogan said, noting that the party had emerged as the winner nationwide by a large margin.

The voting was marred by scattered election violence that killed at least four people and injured dozens of others across Turkey. Unofficial final results were expected late Sunday.

Years of economic prosperity provided Erdogan and his party with previous election victories. But the race for 30 large cities, 51 provincial capitals and hundreds of districts were held as Turkey grapples with a weakened currency, a double-digit inflation rate and soaring food prices.

The high stakes of the local contests were brought into stark display with the deaths of two members of the Islamic-oriented Felicity Party, a small rival of the president’s Justice and Development Party. Felicity’s leader, Temel Karamollaoglu, alleged a polling station volunteer and a party observer were shot by a relative of a ruling party candidate.

The killings weren’t caused by “simple animosity,” but happened when the volunteers tried to enforce the law requiring ballots to be marked in private voting booths instead of out in the open, Karamollaoglu tweeted.

ERDOGAN RENEWS VERBAL ATTACK AGAINST ISRAEL

Two other people were killed in fighting in the southern city of Gaziantep. Fights related to local elections in several provinces also produced dozens of injuries, Turkey’s official Anadolu news agency reported. The exact causes of the fights remained unclear. Election campaigning was highly polarized, with Erdogan and other officials using hostile rhetoric toward opposition candidates.

Erdogan’s ruling party had renewed an alliance with the country’s nationalist party to increase votes. Opposition parties also coordinated strategies and put forward candidates under alliances in an effort to maximize the chances of unseating members of the AKP.

Erdogan’s supporters expressed dismay at losing the capital.

“We did not think that we would lose Ankara in this election,” said Mehmet Akcam, 18. “Ankara will see the consequences of what it did.”

The pro-Kurdish, People’s Democratic Party appeared to have regained seats in several districts in Turkey’s mostly-Kurdish southeast region where Erdogan’s government had replaced elected mayors with government-appointed trustees, alleging that the ousted officials had links to outlawed Kurdish militants.

CLICK HERE TO GET THE FOX NEWS APP

However, the party lost control of two key cities in the region.

The pro-Kurdish party had sat out critical mayoral races in major cities, including Istanbul and Ankara, with the aim of sending votes to a rival secular opposition party to help challenge Erdogan’s party.