The surprise move comes after disagreements between President Maithripala Sirisena and former Prime Minister Ranil Wickremesinghe over economic policy and day-to-day administration of the government.
Maithripala Sirisena installed Sri Lanka's controversial former strongman leader Mahinda Rajapakse as the country's new prime minister on Friday, the president's office said, in a surprise move announced moments after the incumbent premier was sacked.
Sirisena won elections against Rajapakse in 2015 on a platform of economic reform and accountability for atrocities committed during his opponent's 10-year rule at the close of Sri Lanka's bloody civil war.
Colombo was on the verge of facing economic sanctions from Western nations over Rajapakse's human rights record before his government lost office.
Sirisena's office said late Friday that his former foe had been appointed prime minister, and a private TV channel loyal to Rajapakse broadcast a rushed swearing-in ceremony.
But the ousted premier Ranil Wickremesinghe insisted that he was still the legitimate prime minister and would fight his dismissal in court.
"I am addressing you as the prime minister of Sri Lanka," Wickremesinghe told reporters at a nationally televised press conference.
"I remain as prime minister and I will function as the prime minister."
Questions remain over the legality of the move, as a constitutional amendment passed in 2015 had taken away the president's power to sack the prime minister.
"The appointment of Rajapakse as the Prime Minister is unconstitutional and illegal. This is an anti-democratic coup," Finance Minister Mangala Samaraweera wrote on Twitter shortly after the appointment was announced.
The surprise move comes after disagreements between Sirisena and Wickremesinghe over economic policy and day-to-day administration of the government.
The pair were reported to have clashed in the cabinet last week over government plans to lease a container terminal to neighbouring India.
Earlier this year, Sirisena reneged on a pledge not to run for re-election, sparking tensions with Wickremesinghe, who is believed to have his own presidential ambitions.
Sirisena is also believed to be behind a failed attempt to impeach Wickremesinghe in April.
Relations between Sirisena and Wickremesinghe's political parties, who have governed in coalition since 2015, have soured since both suffered humiliating losses in February's local council elections.
Sirisena's United People's Freedom Alliance party quit the coalition on Friday, according to Agricultural Minister Mahinda Amaraweera.
Former president Rajapakse put down the decades-old Tamil Tiger separatist struggle in May 2009 through a military assault that killed up to 40,000 ethnic Tamil civilians, according to rights groups.
Rajapakse's iron-fisted government was also accused of corruption and murdering political opponents.
Sirisena had pledged accountability for war atrocities but has faced international criticism for being slow to deliver on justice.
International rights groups have called for the prosecution of both the military and the Tigers, who were notorious for suicide bombings and enlisting child soldiers.