By Shihar Aneez and Ranga Sirilal
COLOMBO (Reuters) - Former Sri Lankan President Mahinda Rajapaksa was sworn in as prime minister on Friday, after President Maithripala Sirisena sacked incumbent Ranil Wickremesinghe in a surprise move that threatens political turmoil in the Indian Ocean nation.gi
The appointment was confirmed in a statement from the president's office, but Wickremesinghe later told local television he remained the prime minister.
"I retain the confidence of the house. I am the prime minister and I have the majority," Wickremesinghe said. "According to the constitution I'm the prime minister. That is not legal."
Local television pictures had shown Rajapaksa, who last month led opposition protests against the government, being sworn in before Sirisena, surrounded by a number of opposition legislators.
Underlining the risk of chaos in Sri Lanka, where the government had been under pressure over a misfiring economy, Media and Finance Minister Mangala Samaraweera said on Twitter that the appointment of Rajapaksa as prime minister was a violation of the constitution, which was amended in 2015 to curtail the executive powers of the president.
"This is an anti-democratic coup," Samaraweera tweeted.
Earlier Sirisensa's United People's Freedom Alliance (UPFA) had said it would quit the ruling coalition, capping months of rising tensions between the president's bloc and Wickremesinghe's centre-right United National Party (UNP).
UPFA lawmaker Susil Premejayantha told reporters that a new cabinet would be sworn in soon.
The ruling coalition had been further strained in recent days by strong criticism from Sirisena and his allies that ministers from Wickremesinghe's party did not act properly in investigating an alleged assassination plot to kill the president and former Defence Secretary Gotabaya Rajapaksa, the new prime minister's younger brother.
The alleged plot briefly threatened to cause tension between Sri Lanka and India, after a report that Sirisena had accused India's intelligence services of involvement - a claim that New Delhi and Colombo have both denied.
Sirisena, along with some UPFA lawmakers including from his centre-left Sri Lanka Freedom Party (SLFP), formed a coalition government with Wickremesinghe's UNP soon after Sirisena unexpectedly defeated former ally Rajapaksa in a presidential election in January 2015.
The UNP and UPFA, an alliance of several Sri Lankan parties, consolidated their coalition after a parliamentary election in August 2015.
But both coalition partners suffered heavy defeats in local elections in February this year to a party backed by Rajapaksa. Sirisena loyalists backed a no-confidence motion in April against the prime minister, who survived after a majority of legislators voted to support his coalition government.
In early September, Rajapaksa had led thousands of opposition demonstrators who blocked a main road in Colombo in protest at economic hardship and the delaying of provincial polls.
(Reporting by Shihar Aneez and Ranga Sirilal; Editing by Robin Pomeroy and Alex Richardson)