Media playback is unsupported on your device Media caption The BBC's Mishal Husain was one of the first broadcasters inside the school

Pakistan's prime minister has vowed to rid his country of terrorism after a Taliban attack at a school in Peshawar killed 141 people, mostly children.

Nawaz Sharif spoke after talks between political parties about the massacre.

Gunmen went from class to class shooting the students in the Pakistani Taliban's deadliest attack to date. Funerals of the victims are continuing.

The Afghan president says the "time has come" for his country to work with Pakistan to fight "extremism."

Ashraf Ghani said the two countries should "jointly take effective actions" following a surprise meeting with Pakistan's army chief in Kabul to discuss security co-ordination.

New images of the school published by a BBC team that gained access to the site on Wednesday showed the scale and brutality of the attack, with pools of blood on the ground and walls covered in pockmarks from hundreds of bullets.

'Stand united'

The Pakistani Taliban (TTP) said they had carried out the attack against the Army Public School to avenge army-led operations against them in the Khyber and North Waziristan areas.

Image copyright EPA Image caption All seven attackers were killed during the eight-hour siege at the school

Prime Minister Nawaz Sharif said Pakistan stood united to ensure the deaths of the children were not wasted, after meeting party leaders in Peshawar on Wednesday.

In any action against the militants, he said, there would be no distinction between "good and bad" Taliban.

"We...have resolved to continue the war against terrorism till the last terrorist is eliminated," he added.

He also announced an end to the moratorium on the death penalty for terrorism cases, which correspondents say is a move aimed at countering a view held by many Pakistanis that many terror suspects end up evading justice.

Media playback is unsupported on your device Media caption People across Pakistan are marking three days of public mourning

After meeting Pakistan's army chief General Raheel Sharif on Wednesday, Afghanistan's President Ghani said the two countries should "work together in sincerity and jointly take effective actions against terrorism and extremism".

In the past, the two countries have accused each other of allowing cross border attacks by militants.

Image caption Images taken by a BBC team inside a classroom show the level of destruction

Image caption An office belonging the school principal was hit by a suicide bomber

At the scene: Mishal Husain, BBC News

It was a very eerie atmosphere. These were premises that should have been alive to the sound of hundreds of children who studied here and began school as normal on Tuesday. But it was now desolate.

The army has been working through the night to clear the premises of explosives.

There were blood stains running right down the steps and towards the auditorium itself.

There was a child's shoe on one of the steps. The auditorium, where children were taking exams, was one of the places within the school grounds that the militants first targeted.

The chairs that the children were sitting on had been upturned, the place has been turned upside down and I could see the blood stains on the floor right around me.

Pakistani Taliban (TTP) leader Mullah Fazlullah is believed by the Pakistani authorities to be hiding in Afghanistan, and media reports in Pakistan suggest the school attack may have been co-ordinated from Afghanistan.

But the TTP said the attack had been masterminded by its military chief in the Peshawar region, who it said had been in touch with the gunmen throughout the assault.

A TTP spokesman told the BBC they had deliberately killed older pupils and not targeted "small children".

BBC correspondents say the Taliban statement is being seen as damage limitation after the attack was universally condemned in Pakistan for its brutality.

World leaders voiced disgust at the attack. Even the Afghan Taliban have criticised the attack, calling it "un-Islamic".

Image copyright AP Image caption The Pakistani Taliban released this photo of what they say are the militants behind the deadly school attack

The TTP also repeated its earlier claim that only six attackers were sent, contradicting official accounts that seven gunmen were killed.

The Taliban attackers wearing bomb vests cut through a wire fence to gain entry to the school, before launching an attack on an auditorium where children were taking an exam in a siege that lasted eight hours.

Image copyright AP Image caption Upturned chairs and blood stains left in the wake of the attack at the school's auditorium

Image copyright AFP Image caption Funerals for the victims began hours after the attack on Tuesday and continued on Wednesday

"This is not a human act,'' military spokesman Major General Asim Bajwa said during a tour of the school on Wednesday, the Associated Press reports. "This is a national tragedy."

A total of 125 people were wounded at Peshawar's Army Public School, which teaches boys and girls from both military and civilian backgrounds.

Mohammad Hilal, a student in the 10th grade, was shot three times in his arm and legs when the gunmen stormed the school auditorium.

"I think I passed out for a while. I thought I was dreaming. I wanted to move but felt paralysed. Then I came to and realised that actually two other boys had fallen on me. Both of them were dead," he told the BBC.

Prayer vigils are being held nationwide, with Pakistani embassies across the world lowering their flags to half-mast and opening books of condolences.

India's parliament observed a minute's silence in honour of the victims.

Hundreds of Taliban fighters are thought to have died in the recent Pakistan army offensive in the Khyber area and North Waziristan, regions close to the Afghan border.