A gunman has shot dead at least 12 children at a school in the Brazilian city of Rio de Janeiro before killing himself, police say.
At least 12 others were wounded when the man entered the school with two revolvers and began shooting.
The killer has been identified as 23-year-old former pupil Wellington Menezes de Oliveira.
President Dilma Rousseff wept as she condemned the school massacre - the first of its kind in Brazil.
The attack happened at the Escola Municipal Tasso da Silveira school in the western Realengo area.
Officials said Oliveira arrived at the start of the school day and got into the building by saying he had come to give a lecture, but then went into a classroom and began shooting.
Teachers barricaded the doors of other classrooms while children hid under desks.
Some wounded children escaped and alerted police, who rushed to the scene.
Police said the gunmen shot himself in the head after he was confronted by officers.
"The shooting was still going on when I arrived at the school," military police Sgt Marcio Alves told O Globo.
"I found him on the second floor coming out of a classroom. He pointed his gun in my direction, he got shot and fell, and immediately committed suicide."
Officers said the fast response had prevented an even bigger massacre at the school of around 400 pupils.
"If the police did not arrive as quickly as they did the tragedy could have been far worse, because this man had a lot of ammunition and was carrying two guns," police Col Djalma Beltrame said.
Police said they found a rambling letter on his body which showed he was on a suicide mission.
The letter reportedly gave detailed instructions on how his body should be prepared for burial beside his adopted mother.
It asks that "his tomb be visited by a loyal follower of God to pray before my burial asking God forgiveness for what I have done".
"Nothing that is impure can touch my blood," it read.
'Covered in blood'
President Rousseff later said she was shocked by the massacre.
"Innocent children lost their lives and their future," she said, after observing a minute of silence for the victims.
Rodrigo Alves Pereira, who lives in the area, told the BBC that he was in a shop near the school when he heard "a lot of shots coming from inside the school".
"I went out and saw many children... coming out of the school. Some of them were covered in blood, shaken, asking for help. One was injured in the shoulder. They were desperate and crying.
"They said that there was a man wearing a suit who was shooting at school kids in classrooms. He first went to a reading room, talked to teachers there, and then went on to two classrooms. This is a complete tragedy. We are all devastated," Mr Pereira said.
Marcos Silva, 11, who was at the school but was not hurt, said the experience was "like a horror movie".
"Everyone lay on the ground in silence, the teacher asked us not to make a sound so he would not notice us," he added.
"I thought to myself: 'If he comes in, we are all going to die'."
Rescue workers used a football pitch near the school as a helicopter base from which to transport wounded children to the hospital.
Hundreds of people gathered outside the school, either out of curiosity or to check on children who were inside at the time of the shooting, the BBC's Paulo Cabral in Rio de Janeiro says.
The school, in an impoverished neighbourhood of Rio, is attended by pupils aged nine to 14.