ISLAMABAD — Pakistan’s top court dismissed the prime minister from office on Tuesday for failing to investigate the president for corruption, ushering in a new round of political turmoil in a nation vital to American hopes of withdrawing from neighboring Afghanistan.

The Supreme Court ruling against Yousuf Raza Gilani was unlikely to topple the fragile, coalition government. But it left it weakened and without a Cabinet. Most analysts expected the government to heed the court order and begin the process of replacing Gilani, or possibly expedite general elections that must be held before early next year.

The move was likened by some to a “ judicial coup” in a country with a history of destabilizing conflicts between the courts, the army and elected governments. It comes as Pakistan faces near economic collapse, power shortages and its own struggle against Islamist militants behind attacks that have killed thousands of people over the last five years.

The prime minister has refused to step down since he was convicted of contempt of court in April for not asking authorities in Switzerland to reopen a 1990s graft case against his boss, Pakistani President Asif Ali Zardari.

Zardari’s Pakistan People’s Party should have enough support in parliament to elect a replacement for Gilani, but at the likely cost of concessions to its coalition partners.

As a coalition meeting broke up late Tuesday, some media reports said Makhdoom Shahabuddin, the textile minister, was emerging as a consensus candidate.

The ruling was a major escalation in a long-running confrontation between the judges and the government. Supporters of the government, and some independent commentators, accuse the court of pursuing a vendetta against Zardari that threatens the country’s nascent democracy.

Zardari’s critics, on the other hand, maintain that the court is the only institution standing up against the rampant graft — and ineptitude — in his administration.

Sign up for our daily newsletter

Get the best of The Post and Courier, handpicked and delivered to your inbox every morning.