Sri Lanka's sacked prime minister Ranil Wickremesinghe was reinstated Sunday, his party said, ending a 51-day crisis that had paralysed the island nation and pushed it towards debt default. The 69-year-old leader was sworn in by President Maithripala Sirisena, who sacked him on October 26 and triggered a power struggle that brought the country's government to a standstill. Wickremesinghe had refused to step aside since being sacked by in late October and replaced by former leader Mahinda Rajapakse. Sri Lanka had drifted without a functioning government for nearly two months as the rival factions jostled for power in parliament and the courts. Sirisena had vowed to never reappoint Wickremesinghe -- who he publicly castigated in speeches in recent weeks -- as prime minister under his watch. The acrimony between the two was underscored Sunday when Sirisena barred journalists from attending the swearing-in ceremony -- leaving it to Wickremesinghe's legislators to announce the appointment. "We thank the citizens of the country who fought the illegal seizure of power and ensured that democracy was restored," his United National Party of Sri Lanka posted on Twitter. Sirisena's appointee Rajapakse was unable to govern, failing many times to muster a majority in parliament. He was defeated six times on the floor of the legislature before being forced to step down on Saturday. Sirisena suffered a huge setback when the highest court in the country ruled last week that he acted outside the constitution when he sacked parliament in early November. The court also confirmed Friday that Rajapakse and his purported cabinet could not exercise the powers of the office they held. A spokesman for Wickremesinghe said he was expected to form a cabinet in the coming days, with priority given to the 2019 budget, without which foreign debt servicing may not be possible. Sri Lanka had been braced for a government shutdown as parliament failed to approve spending for 2019, and ratings agencies downgraded the country's credit rating amid fears of a sovereign debt default.