The Pakistani city of Peshawar is in mourning after Taliban gunmen massacred scores of children in a gun attack on a school.

More than 141 people, most of them students, were killed and many more seriously injured when the gunmen broke into the school and opened fire.

The Pakistani military said all nine Taliban insurgents were killed, after an eight-hour operation.

World leaders have condemned the massacre as a "heinous" and "an act of horror".

The Taliban had earlier said it had sent six insurgents with suicide vests to attack the school.

Hours into the siege, three explosions were heard inside the military-run high school, and a Reuters journalist at the scene said he heard heavy gunfire.

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.

Bahramand Khan, director of information for the regional Chief Minister's Secretariat, said at least 126 people were killed and 122 wounded.

"It may rise," he said, adding that more than 100 of the dead were school children.

A local hospital said the dead and wounded it had seen were aged between 10 and 20.

The Islamist Taliban movement immediately claimed responsibility.

"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."

It is not clear whether some or all of the children were killed by gunmen, suicide bombs or in the ensuing battle with Pakistani security forces trying to gain control of the building.

Malala 'heartbroken' over Taliban attack

World leaders condemn attack

Children speak of horror during Taliban attack

Q&A - Who is the Pakistani Taliban?

The Pakistani Taliban, which is fighting to topple the government and set up a strict Islamic state, has vowed to step up attacks in response to a major army operation against the insurgents in the tribal areas.

It has targeted security forces, checkpoints, military bases and airports, but attacks on civilian targets with no logistical significance are relatively rare.

In September, 2013, dozens of people, including many children, were killed in an attack on a church, also in Peshawar, a sprawling and violent city near the Afghan border.

With the rescue operation under way, the situation remained fluid, with contradictory reports about what was happening inside the school and witness accounts difficult to come by.

"An army doctor was visiting us teaching us about first aid when attackers came from behind our school and started firing," one student told Pakistan's Dunya Television.

"Our teachers locked the door and we ducked on the floor, but they [militants] broke down the door. Initially they fired in the air and later started killing the students, but left the hall suddenly.

"The attackers had long beards, wore shalwar kameez [traditional baggy clothes] and spoke Arabic."

Prime Minister Nawaz Sharif condemned the attack and said he was on his way to Peshawar.

"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."

The United States condemned the "horrific" attack on the school.

In a statement, the White House said it reiterates US support for the Pakistan government in its efforts to "combat terrorism and extremism".

President Barack Obama said: "By targeting students and teachers in this heinous attack, terrorists have once again shown their depravity".

"We stand with the people of Pakistan, and reiterate the commitment of the United States to support the government of Pakistan in its efforts to combat terrorism and extremism and to promote peace and stability in the region."