Sri Lanka has an undisputed prime minister for the first time in more than 50 days after one of the two men who have claimed to lawfully occupy the post was sworn in on Sunday, a day after his challenger resigned.

Supporters of Ranil Wickremesinghe celebrated the defeat of a “coup” as he signed official papers in Colombo, marking the end of a crisis that had left the country without a prime minister or cabinet and on the precipice of a government shutdown.

But analysts warned of more instability ahead for the Indian ocean island including the possibility of increased anti-western rhetoric and resentment towards the country’s Tamil minority.

Wickremesinghe had planned to be sworn in at 11.16am on Sunday morning, an auspicious time according to the Sinhala tradition, but was delayed by the late arrival of Sri Lanka’s president, Maithripala Sirasena.

It augured poorly for a political relationship that has turned toxic in the past 18 months, culminating in Sirasena’s surprise announcement in October that he was firing Wickremesinghe.

Taking the office for the fifth time in his career, Wickremesinghe said his return was a victory “for Sri Lanka’s democratic institutions”.

Today marks a victory not for myself or for the UNP. It is a victory for Sri Lanka’s democratic institutions and the sovereignty of our citizens. I thank everyone who stood firm in defending the constitution and ensuring the triumph of democracy. — Ranil Wickremesinghe (@RW_UNP) December 16, 2018

Pictures from the ceremony posted on social media by Wickremesinghe’s allies – journalists were prevented from attending – showed the pair grinning with palms clasped towards each other.

But sources in the office said there were testy exchanges immediately after the swearing in, with Sirisena demanding a say in ministerial appointments and Wickremesinghe pushing back.

Sirasena has spent six weeks trying to avoid Sunday’s outcome, even trying to dismiss the entire parliament and call an election once it became clear his chosen successor, Mahinda Rajapaksa, could not command a majority of MPs.

The Sri Lankan supreme court halted the election on Thursday, and on Friday extended a ban on Rajapaksa from exercising any official duties.

It followed weeks of backroom dealing by Rajapaksa to confirm his leadership in parliament and, once that failed, efforts to disrupt the assembly by pelting opposing MPs with books, chairs and water mixed with chilli powder; scenes of chaos on the floor that were broadcast around the world.

On Friday night, the impasse broke, with Rajapaksa signalling he was finally willing to resign from office, clearing the way for Wickremesinghe’s return.

Rajapaksa said in a departing speech the popular momentum behind his party was irresistible and would soon return them to power. “What is now gathering against the enemies of the country is a country-wide political force that no one can stop,” he said.

Some supporters have cast his aborted return as the result of a western-backed conspiracy against a leader who drew Sri Lanka closer to China during his earlier 10-year rule that ended in 2015.

“We fought against foreign intelligence agencies such as CIA and MI6,” said Udaya Gammpilla on Saturday. “We knew it was a tough battle. Foreign diplomats cheered in parliament when the speaker pronounced that we did not have a majority. All of them can sleep well now.”

Wickremesinghe’s government will immediately seek to pass legislation to keep government services funded beyond the budget deadline of 31 December. It will also seek to reassure the country’s lenders including the International Monetary Fund that it can finance its heavy external debts. Ratings agencies have downgraded the country in recent weeks as the political paralysis became entrenched.

Hasnain Malik, the head of equity research at Exotix Capital, said markets would welcome the end of the standoff. “But it also means a return to the political paralysis which has held back growth over the last three years,” he said.

“It seems that only an early election which results in a clear parliamentary majority for either Wickremasinghe or, more likely, Rajapaksa would resolve that.”

“Not much will get transacted in terms of government business and policies,” agreed N Sathiya Moorthy, a director of the Delhi-based Observer Researcher Foundation.

He said Wickremesinghe’s new ruling coalition was dependent on Tamil legislators and would be under pressure to accede to their demands.

That, in turn, could be exploited by Rajapaksa, whose Buddhist nationalist party traditionally takes a hard line on Tamil demands for greater autonomy and accountability for crimes committed during the country’s three-decade long civil war.

“Rajapaksa has already sounded the battle bugle on the Tamil issue,” Moorthy said.