Twenty students and one soldier have been killed in a Taliban attack on a military school in the north-western Pakistani city of Peshawar, a hospital official said.

Jamil Shah, a spokesman for Lady Reading Hospital, said the soldier was a member of the Pakistani paramilitary forces.

The attack started with the gunmen entering the school in the early hours and shooting at random, said police officer Javed Khan. Army commandos quickly arrived at the scene and exchanged fire with the gunmen, he added.

Outside the school, shooting was initially heard, and one loud bang of unknown origin. Details were sketchy in the unfolding situation and it was unclear what was going on inside the school and if any of the students were taken hostage.

Pakistani television showed soldiers surrounding the area and pushing people back.

Later, one of the wounded students, Abdullah Jamal, said he was with a group of 8th, 9th and 10th graders who were getting first-aid instructions and training with a team of Pakistani army medics when the attack began.

When the shooting started, Mr Jamal, who was shot in the leg, said nobody knew what was going on in the first few seconds.

"Then I saw children falling down who were crying and screaming. I also fell down. I learned later that I have got a bullet," he said, speaking from his hospital bed.

"All the children had bullet wounds. All the children were bleeding," he added.

Taliban spokesman Mohammed Khurasani claimed responsibility for the attack in a phone call to media, saying that six suicide bombers had carried out the attack in revenge for the killings of Taliban members at the hands of Pakistani authorities.

Peshawar has been the target of frequent militant attacks in the past.