Sri Lanka’s president has issued a formal notice for Ranil Wickremesinghe to step down as prime minister and recognise his shock dismissal, in an unfolding constitutional crisis.

Hours after sacking his former ally, President Maithripala Sirisena issued gazettes formalising the dramatic move, and the installation of one-time strongman president Mahinda Rajapakse as the new prime minister.

However, Wickremesinghe continued to occupy Temple Trees, the official residence of the prime minister, and insisted in a letter to Sirisena that he was still in office.

He has said that he can be removed only by parliament where his party enjoys a majority, and also vowed to seek legal action against what he condemned as an unconstitutional move against him.

“I am addressing you as the prime minister of Sri Lanka,” Wickremesinghe told reporters at a nationally televised press conference on Friday night. “I remain as prime minister and I will function as the prime minister.”

Since his rushed swearing in, Rajapakse is yet to announce the formation of a cabinet - which under the constitution is automatically dissolved when a prime minister is removed.

The parliamentary speaker, Karu Jayasuriya, has said that he will decide on Saturday whether to recognise Rajapakse or not, after seeking legal advice.

Parliament is not due to meet until 5 November when the 2019 national budget is due to be presented. The supreme court, which is empowered to resolve constitutional disputes, is shut for the weekend and reopens on Monday.

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

Speaking to jubilant supporters outside his Colombo home late Friday, Rajapakse also called on Wickremesinghe to step down.

Members of his party must “respect democracy, respect the country and respect the law”, the former president said through a loudhailer from a balcony.

Rajapakse loyalists stormed two state-owned television networks overnight – which they regard as loyal to the outgoing government – and forced them off the air.

Video footage from private networks showed police overwhelmed by mobs at the Rupavahini national TV station but elsewhere in the capital streets remained calm.

As president for nine years beginning in 2005, Rajapakse crushed the Tamil Tigers in 2009, ending a 25-year conflict, but refused to acknowledge abuses committed during the bloody civil war.

The United States called on all sides in Sri Lanka to operate within the constitution and refrain from violence, and urged the island to move forward on post-war reconciliation.

“We call on all parties to act in accordance with Sri Lanka’s constitution, refrain from violence and follow due process,” the State Department said.

Constitutional lawyers, political activists and pundits have debated on social media and Sri Lankan TV whether Wickremesinghe’s ouster was legitimate. The constitution says the president has the right to appoint someone he thinks has a majority in parliament.

But the 19th amendment, added in 2015, says a prime minister can only be removed when he or she ceases to be a member of parliament such as for failing to meet criteria to be an elector or candidate, when a vote of no-confidence is passed, or when he or she chooses to resign.

“At the moment, there is a constitutional crisis – two persons each claiming to be the prime minister,” said Jehan Perera, executive director of the nonpartisan National Peace Council of Sri Lanka.

“What the president now should do immediately is to summon Parliament and have a vote. That’s the democratic way to resolve this crisis,” Perera said.

Rajapaksa lost a bid for re-election in 2015 amid mounting allegations of corruption and nepotism. Under his former government, dozens of journalists were killed, abducted and tortured and some fled the country fearing for their lives.

His return to power as prime minister could signal that Sri Lanka is sliding back to an era of violence against political opponents, critics and journalists, observers said.