The Sri Lankan president’s sacking of the prime minister and installation of a former strongman has left the country in political limbo.

This week, Sri Lanka’s Supreme Court made a dramatic intervention in the country’s deepening political crisis, a move that may prevent it from sliding further into democratic dysfunction and possible political violence.

The three-judge panel overturned the unilateral action by Sri Lankan President Maithripala Sirisena to illegally dissolve the parliament last week. The ruling means that parliament could reconvene as soon as Wednesday (November 14).

Jubilant supporters of sacked Prime Minister Ranil Wickremesinghe celebrated the decision outside the heavily guarded Supreme Court building in the nation’s capital, Colombo. It is being seen as one of the most significant rulings in Sri Lanka’s history.

How Sri Lanka got to this point

The Supreme Court ruling is the latest twist in a tense political drama that has engulfed the nation since late October, when Sirisena sacked Wickremesinghe and installed civil war strongman Mahinda Rajapaksa in his place. He then called for a snap election on January 5 - an election now in considerable doubt.

Sirisena cited a conspiracy to have him assassinated as a key reason for his actions. But he had no constitutional basis for either the dissolution of parliament or the removal of a sitting prime minister.

The president’s move to dissolve parliament came just days before it was scheduled to reconvene and vote on which of the two men claiming to be prime minister should be actually recognised as holding the job.

Sirisena and Rajapaksa had tried but failed to induce enough MPs to switch sides. Dissolving parliament, however unconstitutional, became their only path to self-preservation.

So… who is the prime minister?

Sri Lanka has a long democratic tradition dating back to British colonial times. It has seen many ups and downs, including a brutal 25-year civil war that ended in 2009 and the rise of an authoritarian-style leader in Rajapaksa (who served as president from 2005 to 2015).

But never before have Sri Lanka’s constitution and its democratic principles been so undermined. Supporters of Sri Lanka’s ousted prime minister march in Colombo. M.A. Pushpa Kumara/EPA

Since his sacking, Wickremesinghe has continued to claim he is the legitimate prime minister with the support of the majority of parliament.

But Rajapaksa has thus far appeared to have the confidence of the president and key state institutions.

Why was Wickremesinghe sacked?

The possible return of Rajapaksa had ignited deep concerns within Sri Lanka and abroad.

It was only three years ago that his own party split and aligned with the major opposition parties to propose Sirisena as a consensus presidential candidate.

Ironically, Sirisena’s election heralded a new “Yahapalana” coalition government, a term meaning “good governance”. But things did not go according to plan.

Read more: Rajapaksa defeat signals the end of a dynasty in Sri Lanka

Sirisena and Wickremesinghe were unable to work together and none of their key promises were met. Meanwhile, the economy went backwards.

The coalition seemed doomed when local elections in February were dominated by a new party, established by the Rajapaksa family.

The final straw was the alleged assassination plot against Sirisena, apparently involving neighbouring India. The plot was raised in Cabinet, but Sirisena was unhappy with the response and acted by sacking Wickremesinghe, claiming his life was in danger.

It was the policy differences between Sirisena and Wickremesinghe, however, that was really at the heart of the discontent. Sirisena declared that if Wickremesinghe returned, he would “not stay one hour longer”.

So what happens now?

Sirisena initially said he suspended parliament last week to allow his “new government” to appoint a Cabinet and present a budget.

Yet, it was allegedly done to provide enough time for the Rajapaksa camp to bribe MPs to his side. One MP claimed to have recorded Rajapaksa’s henchmen offering him US$2.8 million.

Meanwhile, crowds have taken to the streets in support of each side, while Wickremesinghe has remained holed up in the prime minister’s official residence, surrounded and protected by supporters and fellow parliamentarians. Two people have been killed.

History suggests that Rajapaksa would have succeeded in convincing enough of those who opposed him to switch sides. But this is no ordinary power struggle.

Why is Rajapaksa’s possible return so fraught?

Rajapaksa’s presidency was punctuated by his controversial response to the civil war and abhorrent end of the conflict, which saw tens of thousands of innocent people killed.

His rule was increasingly authoritarian, nepotistic and corrupt. At one point, his family controlled more than half of Sri Lanka’s budget, and he’d succeeded in amending the constitution to grant himself more powers and the prospect of a presidency for life. Sri Lanka’s civil war strongman Mahinda Rajapaksa has been installed as prime minister by the nation’s president. M.A. Pushpa Kumara/EPA

And this is leaving aside the geopolitical implications of his presidency and possible return to government. Some commentators have portrayed the current crisis as a power struggle between India and China. And it is certainly true that India would prefer Wickremesinghe, and China, Rajapaksa.

During his time in office, Rajapaksa sought Chinese investment to build a major port in Sri Lanka, leaving the country in serious debt. Unable to pay back the Chinese loans, Sri Lanka was forced to hand over the port to China on a 99-year lease.

Given this history, it’s not surprising China was the first of only a few countries to recognise the Rajapaksa prime ministership.

But in the end, this is really about domestic politics. And whatever happens, a return to violence is a real possibility. The Supreme Court’s intervention has stopped Sri Lanka’s democracy going over the cliff for now. But it remains on the edge.

Rajapaksa’s strategy will be to delay a confidence vote in parliament for as long as possible, and to redouble efforts to convene a majority. But if he fails, he may be tempted to use force to get his way, and Sri Lanka’s democratic deficit will become a gaping chasm.