Militants from the Pakistani Taliban have attacked an army-run school in Peshawar, leaving at least 141 people dead, most of them children.
All six attackers are said by officials to have been killed but the security forces are still checking for bombs they may have left.
Scores of survivors are being treated in hospitals as frantic parents search for news of their children.
The attack is the deadliest ever by the Taliban in Pakistan.
The BBC's Shahzeb Jillani in Karachi says the militants appear to have been intent on killing as many students as possible - rather than taking hostages, as initially thought.
Thousands of Pakistanis have been killed in militant violence in recent years - but the latest attack has caused unprecedented shock.
A Taliban spokesman told BBC Urdu that the school had been targeted in response to army operations.
Hundreds of Taliban fighters are thought to have died in a recent military offensive in North Waziristan and the nearby Khyber area.
Analysis: Aamer Ahmed Khan, BBC News
This brutal attack may well be a watershed for a country long accused by the world of treating terrorists as strategic assets.
Pakistan's policy-makers struggling to come to grips with various shades of militants have often cited a "lack of consensus" and "large pockets of sympathy" for religious militants as a major stumbling-block.
That is probably why, when army chief Gen Raheel Sharif launched what he called an indiscriminate operation earlier in the year against militant groups in Pakistan's lawless tribal belt, the political response was lukewarm at best.
We will get them, was his message, be they Pakistani Taliban, Punjabi Taliban, al-Qaeda and affiliates, or most importantly, the dreaded Haqqani network. But the country's political leadership chose to remain largely silent. This is very likely to change now.
More than 100 of the dead are children, a local official told Reuters news agency, although other sources say the number may be slightly smaller.
The attack started at 10:00 local time (05:00 GMT). Mudassir Awan, a worker at the school, said he had seen six people scaling its walls.
"We thought it must be the children playing some game," he told Reuters. "But then we saw a lot of firearms with them."
Children who escaped from the school say the militants went from one classroom to another, shooting indiscriminately.
One boy told reporters he had been with a group of 10 friends who tried to run away and hide. He was the only one to survive.
Others described seeing pupils lying dead in the corridors. One local woman said her friend's daughter had escaped because her clothing was covered in blood from those around her and she had lain pretending to be dead.
A hospital doctor treating injured children said many had head and chest injuries.
Irshadah Bibi, a woman who lost her 12-year-old son, was seen beating her face in grief, throwing herself against an ambulance.
"O God, why did you snatch away my son?" AFP news agency quoted her as saying.
The school is near a military complex in Peshawar. The city, close to the Afghan border, has seen some of the worst of the violence during the Taliban insurgency in recent years.
Many of the students were the children of military personnel. Most of them would have been aged 16 or under.
Malala Yousafzai, a Pakistani Nobel laureate who was shot by the Taliban for campaigning for the right to an education, condemned the attack.
"I, along with millions of others around the world, mourn these children, my brothers and sisters, but we will never be defeated," she said.
Prime Minister Nawaz Sharif, who has arrived in Peshawar, described the attack as a "national tragedy". Pakistani opposition leader and former cricket captain Imran Khan condemned it as "utter barbarism".
A Taliban spokesman was quoted by Reuters as saying the school had been attacked because the "government is targeting our families and females".