Ankara: Turkish President Recep Tayyip Erdogan’s ruling party suffered a major upset on Monday after local election results showed it lost the capital Ankara and Istanbul after a decade and half in power. Losing the country’s two major cities would be a stunning defeat for Erdogan, a former Istanbul mayor himself, whose ability to win at the ballot box has been unparalleled in Turkish history. Erdogan campaigned hard, portraying Sunday’s vote for mayors and district councils as a fight for the nation’s survival, but the election became a test for his Justice and Development Party (AKP) after Turkey slipped into a recession for the first time in a decade. The opposition CHP party candidate for Istanbul mayor, Ekrem Imamoglu, was leading by nearly 28,000 votes with most ballot boxes counted, Supreme Election Board (YSK) chairman Sadi Guven said. Imamoglu won almost 4.16 million votes while the AKP candidate, former premier Binali Yildirim, won 4.13 million. Both claimed victory in the early hours following a tight race for the country’s largest city after results showing them in a dead heat. “We want to start working as soon as possible to serve people,” Imamoglu told reporters on Monday. “We want to cooperate with all institutions of Turkey to quickly meet the needs of Istanbul.” In Ankara, opposition mayoral candidate Mansur Yavas had 50.89 per cent of votes ahead of the AKP’s Mehmet Ozhaseki on 47.06 per cent, Anadolu state agency reported, with 99 per cent of ballot boxes counted. “Ankara has won. The loser in Ankara is Ozhaseki, dirty politics has lost,” Yavas told supporters who were waving Turkish flags and setting off fireworks at a celebratory rally. But in a sign of possible turmoil ahead, AKP officials said they would challenge the alleged invalidation of tens of thousands of votes in both cities. AKP secretary general Fatoih Sahin said the party will appeal in Ankara, saying the gap between the candidates “will narrow down and I believe it will eventually turn into a positive result for us.” Speaking to supporters in Ankara after Sunday’s polls closed, Erdogan had said the election was a victory for the AKP, which along with its coalition partner, the rightwing Nationalist Movement Party, won more than 50 per cent of votes overall. The loss in Istanbul, analysts said, would be especially sensitive for Erdogan, who grew up in the city’s working-class Kasimpasa neighbourhood, and liked to tell AKP rank-and-file that victory in the city was like winning all of Turkey. “Istanbul is his heart, it’s really important for him, it is the first place they (AKP) started winning,” said Ayse Ayata, political science professor at Middle East Technical University in Ankara. “They have retained their 51 per cent majority in total, which is very important. Had they not, this would lead into a questioning of their legitimacy.” For his supporters, Erdogan remains the strong leader they believe Turkey needs and they tout the country’s economic development over the years he and the AKP have been in power. Rallying his base among more religiously conservative Turks, Erdogan had presented his opponents as enemies of the state, tarnishing them as tied to Kurdish militants of the Kurdistan Workers’ Party (PKK) who have fought a decades-long insurgency.