Pakistani authorities have banned, imprisoned and killed Islamist militants who attack the state.
At the same time, the nation's powerful security establishment has tolerated and often nurtured what it considers "good" insurgent groups who help Pakistan's strategic interests by targeting archrival India, its eastern neighbor, and sowing chaos in Afghanistan, which sits to its west.
Picking and choosing among heavily armed ideologues has always been a dangerous game, but the risks for Pakistan were never more devastatingly clear than on Tuesday, when Pakistani Taliban militants killed 132 children and 16 staff members at an army-run school in Peshawar.
The Pakistani Taliban, a federation of dozens of groups seeking to overthrow the government, are squarely in Islamabad's "bad" category. They have, however, forged close ties with other insurgents, such as the Afghan Taliban and anti-Indian groups, which operate from the same rugged border region, observe similar fundamentalist philosophies and sometimes share foot soldiers.
With Pakistanis demanding the government respond to the Peshawar killings, Prime Minister Nawaz Sharif declared that "there is no difference between good Taliban and bad Taliban" and vowed to redouble military efforts "to clean this region of terrorism." He also called for swift punishment of militants.
But the challenges were immediately evident as Pakistan's anti-terrorism court on Thursday granted bail to Zaki-ur-Rehman Lakhvi, the suspected mastermind of the 2008 terrorist attacks in Mumbai, India. The court decision came over the objections of a prosecutor, signaling the deep division in the army and political establishment over whether to break ties with the militants, who for years have been a cornerstone of the country's security policy, or make more use of them.
"There's reason to be skeptical of Sharif's statements because he's not the man in charge," said Raza Rumi, a Pakistan expert and senior fellow at the U.S. Institute of Peace in Washington. It was the army chief of staff, Gen. Raheel Sharif, no relation to the prime minister, who rushed to Afghanistan after the Peshawar attack to call for the handing over of Pakistani Taliban leaders believed to be living on Afghan soil, Rumi said.
Pakistan's policy has long vexed the United States, its nominal ally, which blamed the army's spy agency, the Inter-Services Intelligence, for supporting groups like the Haqqani network that have carried out major attacks on coalition forces in Afghanistan.
When the Pakistani army launched an offensive in the militant-infested North Waziristan tribal area this year, the United States, having urged such action for years, resumed drone strikes there against the Haqqani network and other suspected militants, often earning sharp rebukes from Pakistani officials.
Pakistan's tribal areas have been a haven for Islamist fighters since the 1980s when hordes gathered there to launch a jihad, or holy war, against the Soviet occupation of Afghanistan. After the 2001 U.S. invasion of Afghanistan, Pakistan granted sanctuary to many of its neighbor's ousted Taliban rulers, viewing them as a hedge against the chaos that could result when American forces withdrew.
The U.S. raid in 2011 that killed Al Qaeda leader Osama bin Laden, who was living near a Pakistani military academy outside Islamabad, fueled even more questions about the security establishment's covert support for extremists.
Launched in the mid-2000s in response to Pakistani army operations in the border areas, the Pakistani Taliban took inspiration from the Afghan Taliban, pledging allegiance to its leader, Mullah Mohammed Omar.
In recent years, as the Pakistani Taliban insurgency has grown and tens of thousands of civilians have been killed, the group has forged alliances with sectarian militias and recruited young fighters from radical madrasas, many of which enjoy financial support from Persian Gulf countries.
"The policy of allowing militant groups to operate on Pakistani soil has proved disastrous," Husain Haqqani, a former Pakistani ambassador to Washington, wrote Thursday in the Indian Express. "Jihadi militants do not accept the neat divisions between global, regional and local conflicts. Once they are convinced of the righteousness of their cause, they are willing to fight and blow themselves up anywhere."
Many analysts say Pakistan's determination to counter the growing might of India — its nuclear rival, from which it was carved in a brutal 1947 partition — fuels its support of militant proxies.
Under new Prime Minister Narendra Modi, India has taken a tough line on pursuing reconciliation with Pakistan. India this year canceled long-awaited talks after Pakistani envoys held a routine meeting with separatist leaders from Indian-administered Kashmir, the border territory that both countries claim in its entirety.
Even as Pakistan has vowed to crack down on extremists, groups that target India continue to flourish.
Jamaat-ud-Dawa, the political arm of the banned Lashkar-e-Taiba militant organization, which was blamed for the Mumbai attack, has been prominent in recent days. Its leader, Hafiz Muhammad Saeed — who is being sought by the U.S., with a $10-million reward for information leading to his arrest — vowed on national television to take revenge on India for the Peshawar massacre.
Rahimullah Yusufzai, a Peshawar-based journalist who closely follows militant groups, said the Pakistani government would be unlikely to crack down on militant groups that focus on India.
"Our problem right now is Afghanistan-based militants," Yusufzai said, and he has seen Jamaat-ud-Dawa activists "busy helping victims of the Peshawar attack at hospitals."
There also have been few signs that the army offensive in North Waziristan has targeted the Haqqani network and other "good" militants, experts said. Pakistani security officials publicly discussed the operation long before it began, analysts say, allowing extremist groups plenty of time to leave the tribal area.
Some fled to Afghanistan, where they have been blamed for a surge in violence there. Others are believed to have taken refuge in other parts of northern Pakistan, including Peshawar.
"There are no authentic reports about the elimination of Haqqani network in North Waziristan," said Ilyas Khan, a journalist in Islamabad who covers the tribal areas.
Pakistani officials are hopeful for a breakthrough under new Afghan President Ashraf Ghani, who received a warm welcome in Pakistan last month and has signaled he wants to make peace with Afghan Taliban insurgents.
Ghani wants Pakistan to help bring Afghan Taliban leaders to the negotiating table, but in return Pakistan would want Afghan security forces to produce Mullah Fazlullah, the leader of the Pakistani Taliban. It's an exchange that Afghanistan's weak security forces might not be able to make.
Meanwhile, many analysts believe the drawdown of U.S. forces in Afghanistan is emboldening the Taliban there. An increase in violence in Kabul in recent weeks suggests the insurgents have staying power and will resist efforts to forge a peaceful settlement with the Afghan government.
Last year, officials in Khyber-Pakhtunkhwa province, of which Peshawar is a part, said in a strategy document that militancy in Pakistan would increase with the departure of coalition combat forces from Afghanistan. The leaked document contended that if Islamabad tried to cut ties with the Afghan Taliban, there would be blowback because of ideological and military links the Afghan insurgents had forged with Pakistani militants.
"What the Afghan Taliban do in Afghanistan, the Pakistani Taliban do here," the Institute of Peace's Rumi said, referring to Pakistan. "The Afghan Taliban attack schools, hotels and markets with these big blasts. It's not as if they have a different strategy of terrorism or violence. They just don't do it against Pakistan. It's a bit crazy."
Times staff writer Bengali reported from Mumbai, India. Special correspondents Sahi reported from Islamabad and Ali from Peshawar.