More than eight hours after militants entered the school compound, the military declared the operation to flush them out over, and said that all six insurgents had been killed.
The attack at a military-run high school attended by at least 500 students, many of them children of army personnel, struck at the heart of Pakistan's military establishment, an assault certain to enrage the country's powerful army.
The Taliban, waging war against Pakistan in order to topple the government and set up an Islamic state, immediately claimed responsibility for the attack. (Read All About Tehreek-e-Taliban Pakistan)
"We selected the army's school for the attack because the government is targeting our families and females," said Taliban spokesman Muhammad Umar Khorasani. "We want them to feel the pain."
As night fell on Peshawar, a teeming, volatile city near the Afghan border, security forces finally wrapped up an operation that lasted more than eight hours and involved sometimes intense gun battles.
The Taliban said the gunmen had been equipped with suicide vests. Three explosions were heard inside the high school at the height of the massacre, raising fears of more casualties.
Outside, as helicopters rumbled overhead, police struggled to hold back distraught parents who were trying to break past a security cordon and get into the school.
Officials said 122 people were wounded. A local hospital said the dead and injured were aged from 10 to 20 years old.
According to early witness accounts, a group of militants burst into the school as students attended classes and lectures, shooting indiscriminately at both pupils and teachers. (Pakistani Student Who Survived Two Bullets Describes The Attack)
The gunmen, who several students said communicated with each other in a foreign language, managed to slip past the school's tight security because they were wearing Pakistani military uniforms, local media reported. (Also Read: I Beg Taliban, Take Me But Leave These Children, Kailash Satyarthi Tells NDTV)
Pakistanis, used to almost daily militant attacks, were shocked by the scale of the massacre and the loss of so many young lives. ('My Son Was in Uniform. Now He is in a Casket': A Father's Agony)
It recalled the 2004 siege of a school in Russia's Beslan by Chechen militants which ended in the death of more than 330 people, half of them children.
A soldier escorts schoolchildren after they were rescued from from the Army Public School in Peshawar. (Reuters)
SPIRAL OF VIOLENCE
The Pakistani Taliban have vowed to step up attacks in response to a major army operation against the insurgents in the tribal areas.
But despite the crackdown this year, the military has long been accused of being too lenient towards Islamist militants who critics say are used to carry out the army's bidding in places like Kashmir and Afghanistan.
In September, 2013, however, dozens of people, including many children, were killed in an attack on a church, also in Peshawar in Pakistan's northwest.
The assault on a school where officers' children studied could push the armed forces into a more drastic response, analysts said.
In Peshawar, with the rescue operation still under way, hospitals overflowed with hundreds of wounded children, teenagers and adults.
"Classes 8-10 were in a special seminar on first aid in the main hall when students heard gunshots and then countless men burst in and opened fire," said Shahrukh Khan, in his mid-teens, who was shot in both legs.
"Teachers and the principal were also there. The men who burst in were speaking and shouting in an incomprehensible language. Sounded like Arabic or Farsi."
Another student told Pakistan's Dunya Television: "The attackers had long beards, wore shalwar kameez (traditional baggy clothes) and spoke Arabic."
Prime Minister Nawaz Sharif condemned the attack.
"I can't stay back in Islamabad. This is a national tragedy unleashed by savages. These were my kids," he said in a statement.
"This is my loss. This is the nation's loss. I am leaving for Peshawar now and I will supervise this operation myself."
In neighbouring India, Prime Minister Narendra Modi echoed Sharif's sentiments.
"It is a senseless act of unspeakable brutality that has claimed lives of the most innocent of human beings - young children in their school." ("Unspeakable Brutality": PM Modi on Pakistan School Attack)
Pakistani teenager Malala Yousafzai, joint winner of this year's Nobel peace prize for her education campaign work, said she was devastated by the news. (Malala "Heartbroken" by Pakistan School Slayings)
"I am heartbroken by this senseless and cold-blooded act of terror in Peshawar that is unfolding before us," Malala, who now lives in central England, said in a statement.
Follow NDTV for latest election news and live coverage of assembly elections 2019 in Maharashtra and Haryana.
Subscribe to our YouTube channel, like us on Facebook or follow us on Twitter and Instagram for latest news and live news updates.