"The dissolved parliament will be reinstated," the court wrote in its judgement.

Oli first moved to dismiss parliament in December, but it was reinstated by the Supreme Court, which called his move unconstitutional.

The 69-year-old then lost a vote of confidence in the lower house of parliament.

But he was reinstated as PM after the main opposition parties were unable to obtain a majority of support in the bicameral parliament.

Oli tried again to dissolve parliament in May, but his decision was challenged by lawmakers and political activists in the top court.

The court said in its judgement that the main opposition leader Sher Bahadur Deuba should replace Oli by late Tuesday, as he had presented "a claim (of majority)... as the prime minister".

Deuba has to win a vote of confidence in the lower house within a month to retain the prime ministership.

Deuba, the head of the Nepali Congress, earlier claimed to have the support of 149 members of the 275-seat lower house.

The Oli government came to power in 2018 with a two-thirds majority.

There was optimism that his strong mandate at the polls would end years of instability and short-lived governments exacerbated by a devastating earthquake in 2015.

Deuba was elected as Nepal's prime minister four times between 1995 and 2018, including during the brutal, decade-long Maoist insurgency.

Read more from Asia