Turkish authorities on Monday ordered a redo of an election won by an opponent of President Recep Tayyip Erdogan’s political party, snatching away a major victory from the country’s opposition.

Under heavy pressure by Mr Erdogan’s Justice and Development Party (AKP) Turkey’s High Election Commission (YSK), which is described as packed with the president’s loyalists, cancelled the results of 31 March Istanbul mayoral elections narrowly won by Ekrem Imamoglu, a rising star in the Turkish opposition.

The news was reported by Turkey's state-run Anatolia News Agency. It sent the Turkish lira, already battered by inflation and high borrowing costs, tumbling.

Mr Imamoglu appearing before a crowd of supporters struck a defiant tone.

"We won this election by the hard work of millions of people; they attempted to steal our rightfully won elections," he said. "We are thirsty for justice. The decision-makers in this country may be in a state unawareness, error or even treason, but we will never give up."

As shock and anger over the news spread, supporters of Mr Imamoglu began banging pots and pans in a cacophony of peaceful protest throughout the city.

"One of the worst days for Turkey’s beleaguered democracy," wrote Asli Adintasbas, a journalist and commentator.

Mr Imamoglu was handed the mandate to govern last month, lifting the spirits of Erdogan’s opponents, despite vague and unsubstantiated accusations of cheating and election fraud by the AKP and its loyalists.

Mr Imamoglu’s victory marked the first time in 25 years that Istanbul, a city of 16 million that is Turkey's economic powerhouse, fell out of the hands of Mr Erdogan’s political party. The AKP also lost control of the capital, Ankara, for the first time in 25 years but with a much larger margin.

The YSK overturned the election results on a technicality, arguing that some of those who served on election boards in the city were not civil servants. Mr Imamoglu mocked the ruling. "With the same election rules, a president has been elected, a referendum has been held, so there is also uncertainty over the Constitution and the President's position," he said.

Mr Imamoglu's opponent, Binali Yilidrim, said he would wait for the final election commission ruling to emerge before weighing in.

Istanbul is a major source of patronage cash, with real-estate deals used to seal ties between the AKP and developers who are the pillar of the party. Municipal election losses enraged AKP supporters, causing division within the party's ranks.

While new elections -- said to scheduled for either 23 June or 7 July -- could bring Istanbul back under the control of the AKP, it also carries political risk, should the party lose by even a larger margin. Already the party's handling of the election loss had made it look petty and power hungry, while cementing the unflappable Mr Imamoglu's stature as a national political phenomenon.