A hostage situation at a Moscow school on Monday ended with all the children freed, but a policeman and teacher were killed. Police said the gunman, who took two dozen 15-year-olds hostage, was a fellow pupil possibly on a revenge mission.

The incident came as Russia stands on high security alert before the Winter Olympics, which start in the southern city of Sochi later this week. The gunman does not appear to be linked in any way to organised terror groups.

The student, named only as Sergei, was armed with two rifles, and forced a security guard at School 263 in north-east Moscow to let him inside the building. He then apparently entered a classroom of about 20 students.

Pupils present told the Russian website Life News that the shooter was wearing a long woman's fur coat, and had two rifles and two bags of bullets.

A statement from Russia's Investigative Committee said that the gunman shot a teacher while on his way to the classroom who later died. Those in the classroom said the gunman entered the room and shot the 36-year-old geography teacher twice in the chest, before aiming a final shot at his head.

"He started telling us how he had come to this, and said that he wanted to know if there is life after death, and came to shoot before he died," said one of the students. Another said it was clear from the gunman's expression that he was very scared, and added that the student had not had previous conflicts with the teacher or any fellow pupils.

Students from other classes were evacuated. When police arrived, the hostage taker shot at them from a window. One policeman later died of his wounds, while another is injured.

Later, the gunman began to speak on his mobile phone, apparently to his father, who calmed him down and persuaded him to give himself up. The siege lasted less than two hours.

A spokesman for the Investigative Committee said he believed the child had suffered an "emotional breakdown".

School shootings are rare in Russia, though the horror of the school siege at Beslan in 2004 is still fresh in the memory. At Beslan, more than 300 children died when Chechen terrorists took hostages in the school gym and Russian troops stormed the building.