THE CRISIS IN U.S. relations with Pakistan has been overtaken, in Pakistan itself, by a power struggle among three competing authorities: the civilian government, the military and the judiciary. Its outcome could determine whether Pakistan will seek to repair its alliance with the United States or become a more open adversary in Afghanistan and elsewhere. Not coincidentally, it will also show whether the country’s powerful military and intelligence service can be checked by civil institutions. Though history would suggest that the generals are bound to win, so far the result has been a stalemate.

At the center of the furor is Pakistan’s former ambassador to Washington, Husain Haqqani, a highly capable representative of the government of President Asif Ali Zardari and a longtime advocate of democracy and civilian rule. Mr. Haqqani was forced to resign his post in November and now is under investigation by Pakistan’s Supreme Court. A Pakistani businessman claimed that Mr. Haqqani helped craft an appeal to the Obama administration to protect the civilian government from a possible military coup; this is being treated as an act of treason. Mr. Haqqani, who denies the story, has taken refuge in the home of Prime Minister Yousuf Raza Gilani. He has good reason to fear he will be targeted for assassination, like other liberal politicians slain in the last year.

Besides the military and Mr. Zardari’s government, the third party to the dispute is the court, which seems to have embraced the generals’ cause of ousting the civilian government. Chief Justice Iftikhar Mohammed Chaudhry has had outsize political ambitions ever since he helped depose former president Pervez Musharraf. He has sought since 2009 to prosecute Mr. Zardari for corruption, even though he enjoys immunity as president. In addition to investigating Mr. Haqqani, the court is threatening to hold Mr. Gilani in contempt for failing to ask Switzerland to reopen a financial investigation of Mr. Zardari.

The good news in this complex struggle is that the case against Mr. Haqqani appears to be crumbling — as it should be — for lack of evidence. Mr. Gilani has pushed back against the military, by firing the defense secretary. And Mr. Chaudhry’s overweening actions have divided a legal community that once supported him overwhelmingly. With luck, Mr. Zardari’s government will survive until an election in March for the upper house of parliament, which the ruling party is likely to win; that could provide more leverage against the generals.

The Obama administration has been outwardly supportive of Pakistan’s civilian government but has often bypassed it, dealing directly with the chiefs of the army and intelligence agency on matters such as Afghanistan. While there is a certain pragmatic logic to this, what the past two years have demonstrated — again — is that an enduring partnership between Pakistan and the United States will be possible only if moderate civilians establish control over the military and dismantle its toxic nationalist agenda, which is founded on enmity toward India and rejects an independent and stable Afghanistan. There may not be much the Obama administration can do to tip the ongoing power struggle in Islamabad, and any overt attempt to intervene would probably backfire. But the administration should be hoping that Mr. Haqqani’s side wins — or at least survives.