Militants from the Pakistani Taliban have attacked an army-run school in Peshawar, leaving at least 135 people dead, most of them children.
Pakistani officials say the attack is now over, with all of the attackers killed, although security forces are still checking for bombs.
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.
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.
An unnamed military source told Reuters news agency that nine gunmen had been killed while other sources said six. Seven soldiers were wounded, the Reuters source added.
First reports spoke of 100 children being killed. However, Pakistan’s APP news agency later said 89 children were among the 135 confirmed dead. It is unclear if the toll includes the attackers.
A further 114 people were injured, the agency added.
It appears the militants scaled walls to get into the school and set off a bomb at the start of the assault.
Children who escaped say the militants then 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”.