Pakistan exemplifies a problem for the United States in the Muslim world, and, indeed, in other parts of the world as well. This is that, on the one hand, US administrations are committed in principle to promoting democracy around the world. They are, of course, equally committed to advance what they perceive to be American interests. The problem is that large democratic majorities in a majority of Muslim countries oppose key American policies and their countries’ collaboration with Washington.

By far the greater part of the US and allied military drawdown in Afghanistan will have to be conducted across Pakistani territory and airspace. And even after most American troops leave next year, the US will retain bases, special forces, and advisors in Afghanistan. These will be in the middle of whatever Afghan situation develops in future — a situation over which Pakistan will have a very major influence.

Closeness to Washington has helped undermine the domestic legitimacy of many Muslim governments — which in turn helps explain why all public rhetoric to the contrary, actual US policy in the Muslim world has so often centred on support for dictatorships. With Pakistani general elections due on 11 May, this question has a new salience. If it is not as acute an issue as it might be, this is partly due to deep pragmatism — thoroughly soaked in cynical self-interest — on the part of the Pakistani civilian political elites, and partly due to the fact that in the end, it is the Army that decides the key issues of foreign and security policy, or at least exercises a veto over them.

Since 2008, America’s dilemma in Pakistan has been somewhat ameliorated by the fact that it had a democratically-elected but basically pro-Western government in power in Islamabad: the Pakistan People’s Party under President Asif Ali Zardari. The PPP’s election victory in 2008 was partly the result of a deal brokered by the Bush administration between the last military dictator, General Pervez Musharraf, and Zardari’s late wife Benazir Bhutto. Much more important was the wave of public sympathy for Zardari and the party when Bhutto was assassinated by the Pakistani Taliban after her return from exile.

All the opinion polls, however, suggest that the PPP is facing a very serious defeat in the next elections, quite possibly losing half its vote and slumping to 15 per cent of the total. How so? Because of (accurate) public perceptions of corruption and incompetence, but also because it has been seen as far too subservient to Washington. Under Pakistan’s first-past-the-post electoral system, the result in terms of seats is unlikely to be so bad. After all, the party’s strong regional bases in the province of Sindh and parts of southern Punjab mean that it can probably continue to dominate these areas. However, during a trip to Pakistan in March, most analysts I met said that it would require something like a miracle for the party to continue to lead the national government.

The biggest winner seems likely to be the Pakistan Muslim League, another dynastic party led by different sections of Pakistan’s political and social elite. The PMLN has a moderate conservative agenda, with a very strong grip on Pakistan’s industrial and agricultural heartland of northern and central Punjab. It will not win an absolute majority — something that has only twice been achieved in Pakistan’s history — but will probably lead a coalition government at the centre.

The PMLN has made some play with anti-American rhetoric, but its bosses, and the industrialists who back them, are well aware of the catastrophic consequences for Pakistan’s staggering economy of a breakdown of relations with Washington. This is not because of US aid, which has been very limited and mostly directed to the military. The real threat would be a loss of US goodwill at the International Monetary Fund, whose loans really have been critical to maintaining even a bare minimum of economic stability, and, in the event of a really serious crisis, the catastrophic menace of US economic sanctions.

There are, however, two very significant potential wild cards in these elections — one old, and one new. The old ones are the religious parties, which have never won more than a small minority of the votes in national elections, but which in 2002 won a majority in the crucial North-West Frontier Province (now Khyber-Pakhtunkhwa). Their rule between 2002 and 2008 is widely blamed for having helped to shelter the growing Pakistani Taliban insurgency in this region. After suffering a severe defeat in 2008, the religious parties are expected to do better this time.

They may be able to form a coalition in Khyber-Pakhtunkhwa with the populist Tehrik-e-Insaf (Justice) party of former cricket star Imran Khan. His party is widely expected to do well, possibly beating the PPP into third place in the national vote and gaining a share of national government. Imran Khan’s support is strongest in Khyber-Pakhtunkhwa, where his party may well lead the government. Like the religious parties, Imran Khan has been a bitter critic of the US “occupation” of Afghanistan, and a strong advocate of peace talks with Pakistan’s own Islamist rebels.

If it happens, this partial ascendancy of anti-American parties will probably not have much direct impact on the US and Western withdrawal from Afghanistan. This area of policy effectively remains firmly under the control of the military. As senior officers told me during my visit to Pakistan in March, they are committed to maintaining their present course, which is to urge Washington to pursue a peace settlement with the Afghan Taliban. They have stated their willingness to influence the Taliban in the direction of a settlement — but only if the US delivers a peace plan which they think that Mullah Omar and his colleagues have some chance of accepting.

When it comes to more direct forms of pressure, the military intends neither to launch any military actions against the Afghan Taliban to push them to make peace, nor to influence the US by interrupting its communications via Pakistan. The only way that this would change is if there were another serious incident with US forces — whether another ground raid into Afghanistan like the one that killed Osama bin Laden, or a repetition of the Salala clash in 2011, when 24 Pakistani soldiers were killed by a US air strike. In this event, the new configuration of Pakistani politics might help drive a tougher Pakistani response than in the past — with disastrous results for US–Pakistani relations.

But the real danger posed by the potential dominance of the conservative, religious, and populist parties relates not to the Afghan, but the Pakistani Taliban. All of these parties have exploited — and encouraged — the general public perception in Pakistan that the Pakistani Islamist insurgency stems from American actions in Afghanistan, and that it should be ended by a negotiated settlement. If elected, they will have to go some distance in this direction.

In the federally-administered tribal areas along the border with Pakistan, this is unlikely to get very far, because the Army have made it very clear that they will not tolerate handing back to the rebels land that the soldiers have reconquered at such high cost, or peace agreements which lead to the military withdrawing to their bases. This they see as a return to the disastrous pattern of 2003–2009.

Elsewhere in Pakistan, however, the lead force in combating extremism is not the army but the police — which is chiefly a provincial subject. There is already circumstantial evidence to suggest a covert agreement between the PMLN government of Punjab and the militants whereby in return for immunity from attack by state forces, the militants promise not to launch terrorist attacks in that province. PMLN leaders have promised to take a strong line against domestic militancy if they form the national government. But such an outcome is by no means certain, and no one can guarantee that the new government of Khyber-Pakhtunkhwa will not allow more space to the rebels.

Even more menacing is the situation in the city of Karachi, where the Pakistani Taliban may be emerging as the dominant force in the city’s huge Pashtun minority, and have in recent months launched ferocious terrorist attacks against their local sectarian and ethnic rivals. Karachi now has a population of some 20 million people. A serious upsurge of violence there, on top of the rebellion in the tribal areas, would test the Pakistani military to the very limit.

In recent years, the war in Afghanistan has meant that in Pakistan, western attention has been concentrated on the Pashtun areas along the Afghan frontier, where militancy has been strongest and where the Afghan Taliban have their bases. However, Karachi is now the third or possibly even the second biggest Pashtun city in the world, after Kabul and Peshawar. Terrorist attacks directed against the West and India can just as well be planned and organised there as in the tribal mountains.

All of this means that Washington has very strong reasons to continue to support the Pakistani state and military to combat the rise of extremism in that country as well as to preserve Pakistan as a state, albeit a deeply imperfect one. These reasons will remain justified after US forces have withdrawn from Afghanistan. Unfortunately, though, the rhetoric that is likely to emerge from parts of the new Pakistani political establishment after the next elections is unlikely to help the Americans remember this rationale, or to win the goodwill of many US politicians.