Sri Lanka's President Maithripala Sirisena. File picture: Frank Franklin II/AP Photo.

President Maithripala Sirisena installed Sri Lanka's controversial former strongman leader Mahinda Rajapakse as the country's new prime minister Friday, in a shock move that plunged the island into an unprecedented constitutional crisis.

Sirisena's office announced the surprise decision moments after the president sacked incumbent premier Ranil Wickremesinghe -- who 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."

There was no immediate comment from Rajapakse, who worshipped at a Buddhist temple shortly after he was sworn in by Sirisena at his office in a ceremony broadcast by a private TV channel loyal to the ex-president.

The president's United People's Freedom Alliance party had earlier Friday quit the coalition that had governed with Wickremesinghe's party. 

Rajapakse ally and opposition legislator Wimal Weerawansa asked Wickremesinghe to step down and allow a smooth transition of power.

Buit Wickremesinghe said he was urging the parliament's speaker Karu Jayasuriya to convene the legislature, where his United National Party still commands a majority.

The speaker said he was seeking legal advice and would announce Saturday if he recognises Rajapakse as the new prime minister.

Sirisena won elections against Rajapakse in 2015 on a platform of economic reform and accountability for atrocities committed during his opponent's 10-year iron-fisted rule which saw the bloody end of Sri Lanka's brutal 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 decision to appoint his former foe prime minister threatens the Indian Ocean island nation with fresh turmoil just as it was trying to emerge from the shadow of the civil war, and the legality of the move is disputed.

A constitutional amendment passed in 2015 removed 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 dramatic developments comes after deepening disagreements between Sirisena and Wickremesinghe over economic policy and day-to-day administration of the government.

- Simmering power struggle -

In May, Sirisena asked his prime minister to end their power struggle and said the coalition should commit to a reform agenda to revive the country emerging from a decades-long ethnic war that claimed more than 100 000 lives.

But Sirisena has 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 have been behind a failed attempt to impeach Wickremesinghe in April.

Rajapakse lost the presidency in January 2015 and the subsequent parliamentary elections in August 2015. 

However, his new Sri Lanka Podujana Peramuna (SLPP) party won local council elections in February and he had been attempting to engineer a dramatic comeback ahead of presidential elections slated for 2019.  

The strongman 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.

His regime refused to even acknowledge war-era abuses, and bitter divisions between minority Tamils and majority Sinhalese persist. 

Rajapakse's hardline government was also accused of corruption and murdering political opponents. Several of Rajapakse's close family and associates face several corruption prosecutions.

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.

The legacy of the conflict has proved a divisive topic in parliament. 

Earlier this month, lawmakers passed legislation to pay compensation to victims of the island's brutal civil war, but Rajapakse's supporters voted against the bill, arguing that it amounted to compensating separatist Tamil rebels.