Meanwhile, the supreme court has applied stringent pressure on the ISI and its sister agency, Military Intelligence, to answer for their activities in the western province of Baluchistan. Human rights groups say that nationalist rebels there are regularly detained by intelligence operatives, tortured and sometimes summarily executed.

The Pakistani news media, which have long handled the military with kid gloves, have seized on the recent cases with a newfound aggressiveness, adding to the public perception that the military has been put on the defensive like never before. Yet for all the public humiliations, few believe the military’s actual grip on power, or the influence it can wield against President Asif Ali Zardari’s civilian government, has waned much. And the generals, while accepting some of the criticism, have also shot back, appearing to signal that enough is enough.

In the most notable case, General Kayani issued a rare public statement this month in which he made a veiled but hard-hitting criticism of the judiciary and the media. The statement has been the subject of frenzied speculation in newspaper editorial pages ever since.

Senior generals insist that, in a country besieged by fractious politics and myriad violent conflicts, the unified and disciplined army is the glue that holds it all together. They are angered that their blood sacrifice against the Taliban in the northwest, and against nationalists in Baluchistan — a conflict they insist is being primed by Pakistan’s archenemy, India — has been overshadowed by human rights concerns.

Some analysts worry that the sudden surge of judicial and media pressure against the military, which was already bristling after the humiliation of the American commando raid that killed Osama bin Laden last year, could be moving dangerously fast. General Beg, the former army chief, has gone so far as to warn that the court’s activism risks triggering a fresh coup.

Few believe that is likely, at least in the short term. But the bubbling judicial confrontation has certainly injected an unpredictable element into the country’s power dynamics as it moves toward elections, to take place within the next seven months.

Leading the charge from the judiciary’s side is the independent-minded chief justice, Iftikhar Muhammad Chaudhry, whose spirited court proceedings are supported by the rowdy and loose coalition of Pakistani lawyers whose street protests in 2007 ultimately helped push President General Pervez Musharraf from power. Now they have the army in their sights. On Wednesday, lawyers of the Rawalpindi District Bar passed a resolution against what they termed the army chief’s interference in politics.