A few months ago, Pakistan looked as though it was falling apart. The Taliban were solidifying their hold on territory in the north and staging shocking attacks deeper and deeper in Pakistan's heartland.
Though the situation in Swat Valley is improving, the success of the Army is upsetting Pakistan's fragile internal balance of power.
As part of a last-ditch effort to stem the violence, the civilian government in April voted to cede control of the Swat Valley to the Taliban. Sharia law was enacted in the region, hundreds of girls' schools were closed, several policemen beheaded, and a video of the flogging of a teenage girl made it to the Internet, horrifying audiences in Pakistan and abroad. Just as bad, the Taliban were not satisfied and moved forward into Buner district, only 60 miles from Islamabad.
Public outcry over these events was directed at the Army, which seemed to refuse to fight a looming internal enemy (the Taliban) in order to prolong an unnecessary rivalry with an external one (India). Commentators in Pakistan and abroad blasted the Army for secretly supporting the Taliban and other terrorist organizations in order to foment trouble with India.
The Obama administration stressed the need for conditions on US military aid and vowed not to write a "blank check" for Pakistan's Army. At the time, it seemed that this overpowered, overfunded behemoth was destroying the country.
In response to the growing uproar – and after several attacks on its own facilities and men – the Army began counterinsurgency operations in the Swat Valley district in mid-May. By June it had recaptured several cities and was well on its way toward a victory against the Taliban in Swat. By July, it was wrapping up the campaign.
This push has generated a storm of news coverage.
On the one hand, there is deep concern for the 2 million or so refugees left in the wake of the fight. On the other, the military has received a fair share of commendation for its successes and for finally fighting "the right war" – the war against the Taliban.
Yet even as the overall situation in the Swat region improves, Pakistan's basic problem remains: From its inception, the Army has consistently and successfully competed with the civilian government in Islamabad for supremacy.
Now, the balance of power between the Army and Islamabad is shifting once more in the Army's favor. After the dust settles in the region, it is not clear that the generals will be willing to return to the barracks.
Historically, military leaders have been able to capitalize on situations such as this, when Islamabad's ability to maintain law and order slips away. In 1958, Gen. Ayub Khan toppled the civilian government amid unrestrained violence in Baluchistan. And in 1999, after a decade of rampant corruption and intense fighting in Karachi, Gen. Pervez Musharraf and his Army seemed like the only force that could restore order.
Today, the credibility of the civilian government is similarly low.
First, approval ratings for President Asif Ali Zardari hover around 20 percent. His government is proving ineffectual against the economic crisis, failed to provide relief for the Swat refugees, or to rebuild the villages to which they will soon return, and is plagued with allegations of corruption and of being hamstrung by inter-party fighting.
Second, Islamabad may simply be on the wrong side of history when the Taliban is defeated, having been unable to stop them from infiltrating Swat and then having officially handed the territory over to them.
These trends are enough to tilt things in the Army's favor. But as Islamabad's star is setting, the Army's is rising. Plaudits for the victory over the Taliban will be awarded to the troops; approval of the Army grows with every recaptured village.
And beyond public approval, the Army's power in real terms is also increasing. Washington nearly doubled its promise of $400 million in military aid to $700 million recently, though it also increased civilian aid. The Army is also reportedly expanding its stockpile of nuclear weapons, which are of little use for counterinsurgency.
For the time being, the Army and the civilian government appear to be working together against a common enemy. However, it is worth remembering that the Army only started operations in Swat in earnest after it was attacked several times by the Taliban. The extent to which the Army is doing the civilian government's bidding is unclear. It would not be surprising, given the sudden shift in the balance of power in Pakistan, if Islamabad were no longer calling the shots.
The Army is unlikely to march straight from Swat to the capital. For now anyway, they are stepping up operations in Waziristan. But the end of the battle with the Taliban will be the beginning of the war for Islamabad. To survive, the civilian government will need to start focusing on its own "right war" – its dangerous power struggle with the Army.
Kathryn Allawala works at Foreign Affairs magazine.