There is no longer a straight fight for power between the Pakistan military and politicians – the courts are involved too

In Pakistan, military coups are true to type. Or at least they were. Just over 12 years ago, when General Pervez Musharaf ousted a civilian government, televisions across the nation went blank one evening until the country's new leader appeared on the screen in the small hours of the morning in combat fatigues to explain that the army had stepped in "for the good of the nation". Other generals in two preceding coups – in 1958 and 1977 – had used similar rhetoric.

For many observers, Pakistan appears on the brink of another coup. Relations between the army and the civilian leadership are poor and deteriorating fast. President Asif Ali Zardari, the widower of Benazir Bhutto, is deeply unpopular and seems incapable of acting to bring his nation out of a cycle of violence, economic failure and administrative incompetence. Prime Minister Yusuf Raza Gilani has no power base of his own. Opposition candidates who are close in views and spirit of the military if not actually linked to it – such as cricketer turned politician Imran Khan – are gaining momentum. The military have run Pakistan for more than half its 64-year existence and seem set to once again.

Yet, as ever, the situation in Pakistan is much more complicated than meets the eye. There is no longer a straight fight for power between the military – who claim that their frequent interventions in politics are rendered sadly necessary by the poor quality of civilian rule – and the politicians – who claim that repeated bouts of military rule have fatally undermined democratic institutions. There are other players too whose often unpredictable actions constrain the actions of all parties. This is no longer two wrestlers seeking to gain a hold on one another but a melee featuring at least half a dozen protagonists .

So, though the furore surrounding a secret memo supposedly sent by a close ally of the president to senior US military officers calling for American intervention to bolster Pakistan's government and cut its army down to size may have made the tensions between the elected civilian leadership and the military very clear, it is in fact the courts that are hounding Zardari and Gilani .

On Monday the Pakistani prime minister was threatened with jail for contempt by the supreme court and ordered to appear before judges, raising the possibility that he could be disqualified from office. His alleged offence is to refuse to reopen corruption investigation into the president, who is also chairman of the ruling Pakistan People's Party. Zardari, who was dubbed "Mr Ten Percent" for his rumoured propensity for demanding kickbacks on government contracts, has presidential immunity. Gilani does not and may have to resign.

That the courts are so involved underlines how the Pakistani senior judiciary, though perhaps justly accused of partisanship, is an important player in its own right and that, if regime change is really what it wants, the army would be forced to deliver some kind of "judicial" or "soft" coup rather than the "tanks in the street" variety. Why this weakness?

Firstly, military commanders believe that, fractious though the alliance is, their relationship with America and the financial aid it brings is still of considerable benefit to the country as a whole and, perhaps more pertinently, to the institution they run. A coup would force a total rupture with Washington.

The international community is no longer as permissive of military takeovers as it once was.

Secondly, the army is very aware of public opinion and knows that the unpopularity of the civilian government does not necessarily translate into support for a military takeover.

Thirdly, Pakistan at present has – thanks in part to reforms effected by the previous military dictator Musharraf – an extremely vociferous media. The enduring image of the 1999 coup is that of soldiers shinning up the gates of Pakistan Television (PTV), the state-controlled broadcaster. These days no one watches PTV and seizing several TV networks is unfeasible.

Yet deeper trends are at work in the army's favour. In the last 20 years – and particularly over the last decade – Pakistan has become economically, culturally and religiously closer to the Middle East. Rapid growth of cities and an economic boom has created a much larger educated, urban middle class. As across much of the Islamic world – in Turkey, Morocco, Indonesia and to an extent in Egypt – this emerging class is not necessarily secular and pro-western but socially conservative, pious and patriotic. Cricketer turned politician Imran Khan represents their worldview and is at the top of the polls as a result.

Significantly too, Pakistani army officers have been drawn in recent decades not from the landed, westernised elite represented by Zardari but more from the "emerging urban centres", which, as the historian of the Pakistani army, Shuja Nawaz, has noted, are "the traditional strongholds of the growing Islamist parties and conservatism".

This means that the administration is being squeezed by greater forces than simply some grumpy generals. Tanks may not roll down Islamabad's streets yet. An early general election this year seems more likely. But either way some kind of change seems inevitable.