Rio de Janeiro schoolchildren flee gunman Reuters

A gunman opened fire at a school in Rio de Janeiro, killing at least 12 children, mostly girls aged between 11 and 13, in what Brazilian media described as the worst school massacre in the country's history.

Ten of the victims were shot in the head or chest by the 23-year-old gunman, who was named as Wellington Menezes de Oliveira. Another 18 people were reported to have been injured, several seriously, before Oliveira killed himself.

Witnesses said Oliveira, a former student of the Tasso da Silveira school in Realengo, in western Rio, approached the school with two handguns just before 8.30am and opened fire on two boys on a nearby street. He shot one in the head and one in the arm.

Oliveira is then said to have continued through the school's metal gates and through its front door where a yellow sign reads: "Smile: you are being filmed."

Dorival Porto Rafael, a rubbish collector who was at the school, told Globo online that the gunman had walked into a class where students were studying Portuguese.

"He came into the class saying he was going to give a talk. He went to an eighth-grade class, on the [ground floor], and without saying anything took out a pistol from his bag and started firing," Rafael said. "The police arrived and he tried to go up to the next floor, but when he saw he was surrounded he shot himself in the head."

Authorities said Oliveira's killing spree ended only because of the intervention of a military policeman who managed to shoot him in the leg before he took his own life.

Crowds jeered as the killer's body was carried out of the school and bundled into a yellow morgue van, wrapped in a black plastic bag.

Brazil's president, Dilma Rousseff, has declared three days of national mourning.

Speaking at a hastily arranged press conference on the school's tatty basketball court, the mayor of Rio de Janeiro, Eduardo Paes, said the tragedy might have been much worse without the policeman's intervention. "God willing, those who are still in danger will not die," he added.

Rio's governor, Sergio Cabral, said Oliveira had been "heavily armed with two guns and a belt filled with professional ammunition".

"I believe it is our duty to … support the families of the young boys and girls killed by this psychopath, this animal," he added.

President Rousseff said: "We must unite in rejecting this act of violence … against defenceless children — children who have lost their lives and their futures."

One witness told the Guardian he had seen between 15 and 20 children dead or seriously wounded.

"It is a massacre, a true massacre," said Roni de Macedo, a firefighter who arrived on the scene shortly after the shooting began and dragged eight seriously injured children from the school.

"There is blood on the walls, blood on the chairs. There are 15 to 20 dead I think," he said, covered in blood from head to toe. "I've never seen anything like this. It's like something in the United States."

Hercilei Antunes, 44, a postman who lives opposite the school and has a daughter there, said: "I saw a load of injured kids, bleeding kids. I saw a dead guy inside. I heard more than 30 shots.

"I heard shots, shots, shots and more shots. I tried to go in, but he shot more and I am not made of steel," he added.

Antunes's porch was blood-stained where he had given first aid to injured children as they fled the school.

With police helicopters hovering overhead, Yvonette Fernandes wept as she looked for her 12-year-old niece, along with scores of other desperate family members. "Where is she? I want to know where she is."

Some students recounted lucky escapes. Sidcley Lopes Garcia, 13, said he had arrived late for class and was outside when he heard the first shots. "I jumped over the wall," he said. "Lots of my friends were injured."

Another 12-year-old student stood outside the school weeping. "I thought I was going to die," she cried. "He shot my friend. My friend is dead."

Twins Brenda and Bianca Rocha Tavares, 13, were inside the school at the time of the shooting and were both hit. Brenda died after being shot in the head, while her sister was shot in the arms and taken to hospital for surgery.

"I was working when I heard about the shooting and came here," Perla Maria dos Reis Paes, their aunt, told O Globo."Unfortunately my niece is dead."