Taliban gunmen and suicide bombers have killed more than 140 students and teachers at an army-run school in the northern city of Peshawar.
The chief spokesman for the Pakistani Army, Asim Bajwa, said six Taliban militants have been killed but IEDs planted by the terrorists made the evacuation of hostages difficult.
Shortly before 6.30pm local time - more than eight hours after the attack started - police said that all militants were dead and the siege was over, AFP reported.
Military officials said 141 people - including 132 children and nine staff members - were among the dead and many more were injured at the Army Public School.
Many were believed to be killed in a suicide blast after the attack started at 10am local time and further explosions were heard later in the day.
Military sources said one teacher was doused with petrol and burned alive in front of pupils who were forced to watch and a suicide bomb was reportedly detonated in a room containing 60 children.
There were unconfirmed claims that children from military families were separated from their peers and shot in the head.
Soldiers had swept the school as the siege started, evacuating the "bulk" of students and teachers from classrooms and rescuing small groups as the day continued.
A spokesperson for the Taliban told international media that suicide bombers had been sent into the Army Public School to target army personnel and their families but were ordered not to harm young children.
Muhammad Khorasani told AFP: “They [military] was always wrong about our capabilities. We are still able to carry out major attacks. This was just the trailer.”
He said the massacre revenge for an anti-terrorist operation launched by Pakistan's army, targeting the school because of its military association.
“We selected the army's school for the attack because the government is targeting our families and females,” Khorasani said. “We want them to feel the pain.”
There were fears the death toll could rise after three loud bangs believed to be explosions were heard hours after the siege began. Ambulances were seen entering the school area and security sources reportedly believe there are bodies still inside.
Shah Farman, the Khyber Pakhtunkhwa Minister of Information, said between 80 and 100 people were believed to be dead.
"The army is trying hard to bring the situation under control," he added. "The operation is currently underway.
"It is unfortunate that schoolchildren were targeted. We need the country to be united and we need justice."
Pakistan's Prime Minister, Nawaz Sharif, has travelled to the scene of the attack in Peshawar.
"These are my children and it is my loss," he said.
Journalists at the scene could hear heavy gunfire from inside the school as soldiers surrounded it and ambulances took wounded children to the hospital.
“We were standing outside the school and firing suddenly started and there was chaos everywhere and the screams of children and teachers,” said Jamshed Khan, a school bus driver.
About 500 students and teachers were believed to be inside at the time, with some taking first aid lessons.
"After half an hour of the attack, the army came and sealed the school," a teacher who escaped told a private television channel.
"We were in the examination hall when the attack took place," he said. "Now the army men are clearing the classes one by one."
One of the wounded students, Abdullah Jamal, said that he was with a group of teenagers who were getting first aid training with a team of Pakistani army medics when the violence began.
He said no one realised what was happening until they "saw children falling down who were crying and screaming" as they were shot.
"I also fell down. I learned later that I have got a bullet,” he said from his hospital bed, where he was being treated for a gunshot wound to his leg.
“All the children had bullet wounds. All the children were bleeding."
Eyewitnesses said the attackers were dressed in army uniforms and set fire to a vehicle before entering the school and opening fire.
Military officials said at least six armed men had entered the Army Public School but did not confirm the number of casualties.
"Our suicide bombers have entered the school, they have instructions not to harm the children, but to target the army personnel,” a spokesperson for Tehreek-e-Taliban Pakistan (TTP), or Pakistani Taliban, told Reuters.
"It's a revenge attack for the army offensive in North Waziristan," he said, referring to an anti-Taliban military offensive that started in June.
David Cameron expressed his sympathy on Twitter. "The news from Pakistan is deeply shocking," he wrote. "It's horrifying that children are being killed simply for going to school."
Additional reporting by agencies
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies