IT IS said that the army chief is the most powerful man in Pakistan. Even so, the prime minister, Nawaz Sharif, made a point of keeping the new head waiting for as long as possible. Breaking with the convention that gives the new chief a month or two to prepare, Mr Sharif named a successor just two days before the outgoing chief, General Ashfaq Parvez Kayani, a former spymaster turned double-term army chief, was due to retire. Lieutenant General Raheel Sharif (no relation to the prime minister) will now control not only a vast army and the world’s fastest-growing nuclear arsenal, but a business empire ranging from cornflakes to luxury housing.

So why the delay? The prime minister is not always decisive, and bear in mind that the last time he picked an army chief, Pervez Musharraf in 1998, his appointee ousted him in a coup a year later. Others, however, suspect an attempt by Mr Sharif to assert civilian authority over an army that needs to be put in its place.

The army sees itself as both embodiment and guarantor of the nation. Yet it has long been at the root of Pakistan’s deepest problems. By meddling in elections and mounting coups, it has weakened the political classes, whose consequent ineptitude and corruption gives it cause to meddle again. It has a history of disastrous military adventures. And it has made common cause with militant Islamists who it hoped would further its interests abroad—keeping India on edge to the south and sowing confusion in Afghanistan to the north in hopes of preventing anti-Pakistan forces growing there.

The country is now paying a terrible price for its sponsorship of foreign terror. It has spawned dozens of local extremist groups attacking Pakistan itself. Since 2001 nearly 50,000 Pakistanis have died in terror-related violence.

For a long time the generals refused to see the Islamists for the threat they are. Officers from the army’s spy wing, Inter-Services Intelligence (ISI), were probably involved in funding and planning deadly attacks in Mumbai in 2008 carried out by Lashkar-e-Taiba. General Kayani may have been as bad as the rest. While he was rising to the top, the Afghan Taliban regrouped, the Mumbai attacks were planned, and Osama bin Laden settled in a garrison town.

Yet along the way the soldier-spy grew into the pragmatist committed to getting the army “out of the driving seat” and nurturing Pakistan’s return to democracy. He and Mr Sharif seem to have got on, while the Americans respected him. Crucially, says Asad Munir, a retired ISI brigadier, he began to understand the nature of the existential threat posed by militant Islam. Military force is required to take it on, particularly in North Waziristan, a tribal area which an alphabet soup of al-Qaeda affiliates have made their base.

General Sharif’s appointment was a surprise. But the good news is that he shares General Kayani’s thinking on domestic militancy. In charge of army training, he was closely involved in efforts to retool an army trained for set-piece battles with India for counter-insurgency in the country’s wild tribal west. Like General Kayani, he knows first-hand the futility of peace accords that militant groups soon renege on.

The problem is that the prime minister has yet to produce a national counter-terrorism strategy and says peace talks must be tried first. It is a cause with minimal chance of success, but one hotly promoted by much of the political establishment. Many more innocent lives may have to be lost before the politicians find the nerve for a military solution.

Elsewhere irritation with civilian government is already flowering among junior officers. But there is no mood to take over. Mr Musharraf’s eight years in power were a disaster (unlamented, he now awaits trial). The army’s once-unchallenged authority has leeched away to a set of rambunctious broadcast media, an activist supreme court and civilian politicians who this year successfully transferred power from one elected government to another—a first for Pakistan. Good governance is the best way for civilian rulers to keep the army off their backs.

Still, the army can always play a spoiling game, especially when it comes to relations with India. It makes no secret of despising Mr Sharif’s enthusiasm for a rapid normalisation of relations, and opposes a crucial free-trade deal. And even as Mr Sharif dreams of visa-less travel across the Indo-Pakistani border, after years of relative calm the ceasefire line in contested Kashmir has become hot again. The officers probably deserve some of the blame for that.