Sri Lanka's crisis looked over on Saturday as strongman Mahinda Rajapakse bowed out of a power battle that had crippled the strategically located island for seven weeks and sent it heading for a possible debt default.
Rajapakse held a multi-religious service at his home where he signed a letter backing down from the post of prime minister controversially conferred on him in October 26.
The 73-year-old ex-president made no immediate statement to reporters, but his aides said he was returning a fleet of limousines he had used since his disputed appointment.
President Maithripala Sirisena triggered the political turmoil by sacking premier Ranil Wickremesinghe and replacing him with his flamboyant former foe Rajapakse.
But Wickremesinghe refused to step down insisting that his sacking was illegal, leaving the Indian Ocean nation of 21 million people with two men claiming the premiership.
Rajapakse was then defeated in a no-confidence motion on November 14.
However, the following day, Speaker Karu Jayasuriya ruled that he would recognise neither man as prime minister, leaving Sri Lanka effectively without a government.
The country was then heading for a government shutdown as parliament failed to approve spending for 2019 and credit rating agencies downgraded its debt amid fears of default.
Rajapakse's son Namal had announced Friday that his father -- who as president ended Sri Lanka's civil war in 2009 amid allegations of grave rights abuses -- would throw in the towel "to ensure stability".
Rajapakse's decision came after the Supreme Court confirmed that he could not exercise the powers of a prime minister until he proved his legitimacy, which without enough support in parliament was impossible.
In a major climbdown, Sirisena agreed on Friday to reinstate Wickremesinghe on Sunday despite previously insisting he would never reappoint him as prime minister.
There was no immediate comment from Sirisena or his office on Saturday.
But an MP from his party, Lakshman Yapa Abeywardena, told reporters on Friday night that the president agreed to the latest measures to avoid a government shutdown after December 31.
"If the stalemate continued, we would have ended up without a budget for 2019 and the government would not have been able to function," Abeywardena said.
On Wednesday, the legislature had voted overwhelmingly to demand the reinstatement of Wickremesinghe.
The leftist JVP, or the People's Liberation Front, insists that Sirisena should be investigated for orchestrating what they call a coup and that there should also be an impeachment process.
On Thursday Sirisena suffered a major blow when the Supreme Court ruled that he had breached the constitution on November 9 by dissolving parliament and calling early elections.
His sacking of parliament had earlier been suspended, but the legislature descended into farce on multiple occasions with MPs throwing punches, hurling projectiles and chili powder and boycotting proceedings.
Sri Lanka’s former president Mahinda Rajapakse gestures during a ceremony before signing a document backing down from his controversial appointment as prime minister in Colombo