A 12-year-old boy in a school uniform blew himself up at a Pakistani army recruitment centre on Thursday, killing 31 cadets, officials said, in an attack that challenges government assertions that it has weakened militants.
The army has carried out a series of offensives against the al Qaeda-linked Pakistani Taliban movement, which claimed responsibility for the attack.
Operations in lawless tribal areas along the Afghan border have failed to break the resolve of Taliban fighters determined to destabilise the U.S.-backed government.
The brazen bombing in the northwestern town of Mardan suggested militants are regrouping after a lull in major attacks.
In a sign of how nervous the government is about security, soldiers at the gates of the military compound searched drivers before allowing them to transport coffins inside.
Militant operations in recent months have been mostly sectarian and have not focussed on military targets.
The bomber struck recruits when cadets were busy in their morning training, a military official told Reuters. At least 20 people were wounded.
The boy apparently walked into the compound, officials said.
It seems the Taliban are still a very potent force because they continue to attack installations, even if they have been quiet for a time, said former general Talat Masood.
They reassert themselves after a while, and it will be a while before we consider them to be less of a threat.
The Taliban have previously launched bold attacks on the military, nuclear-armed Pakistan's most powerful institution.
Last March, two suicide bombers killed at least 45 people in the city of Lahore, including nine soldiers.
In 2009, Pakistani Taliban militants disguised as soldiers attacked the army's headquarters in Rawalpindi and later took 42 people hostage in a nearby office building.
Prime Minister Yusuf Raza Gilani condemned Thursday's attack at the Punjab Regiment Centre.
Such cowardly attacks cannot affect the morale of the security agencies and the resolve of the nation to eradicate terrorism, he said in a statement.
Gilani's government faces pressure on several fronts.
It is trying to revive a stagnant economy propped up by an $11 billion (6 billion pounds) International Monetary Fund loan which requires politically sensitive reforms.
Public discontent is growing over official corruption, rampant poverty and power cuts.
Washington, the source of billions of dollars in aid, is pressuring Pakistan to intensify its fight against both domestic militant groups and ones that cross the long, porous border to attack Western forces in Afghanistan.
Tensions between the allies are also running high over the case of Raymond Davis, who killed two Pakistanis in late January.
Davis, the U.S. embassy in Islamabad says, is a diplomat who acted in self-defence when he shot two men in the middle of a busy Lahore street on January 27. He thus enjoys diplomatic immunity and should be released according to international law and custom.
The Pakistanis say it is a matter for the courts to decide and have moved to charge Davis with two counts of murder. Handing him over to the Americans would deepen anti-American sentiment in Pakistan.