Ten girls and two boys between the ages of 12 and 15 were gunned down, most shot in the head at point-blank range by 23-year-old Wellington Oliveira, who shot and killed himself after being confronted by police.
At least 12 other students were injured in the Thursday shooting at the Tasso da Silveira public school. Two are in grave condition.
Neighbors wandered past the school in a shocked daze Friday, leaving flowers along the wall of the school in western Rio's working-class Realengo neighborhood. Twelve crosses were left along a wall just outside the school, the name of each child killed written on white pieces of paper above them.
Officials posted the schedule for 12 funerals on the school gate. On a blackboard in the school yard, teachers left messages imploring for better security in Brazil's schools. One read, "The Carioca family is in mourning" - Carioca being the nickname for natives of Rio.
Guvete Antunes lives across the street from the school, sobbed as she tried to make sense of the massacre.
"What an absurd thing that happened!" she said, looking at the crosses and flowers outside the school. "I never thought anything like this could happen here. Children came running out of that school, desperate, with gunshot wounds, banging on my door and screaming, 'Auntie, please help us!"'
Brazilian tradition stipulates that people be buried the day after their death, and President Dilma Rousseff was expected to arrive in Rio to attend some of the funerals.
The shock of the killings reverberated across Brazil.
"This is completely outside of our reality. This gunman lived in his own sick world and unfortunately brought his ugliness into ours," said Rivaldo Silva, eyes brimming with tears as he looked at newspaper headlines at a newsstand in central Sao Paulo. "I'm certain he was sent straight to Hell."
The shootings turned the school, which was celebrating its 40th anniversary Thursday, into a nightmarish scene, with bullet holes and blood marking the walls of classrooms.
Witnesses said the gunman stalked the halls of the elementary school he attended himself years before, lining up most of the children he killed and shooting them in the head, one after another, as they begged for him to stop.
Oliveira took his own life after police gunfire struck his legs and sent him toppling down some stairs, but not before carrying out what crime experts said was the worst school massacre in Brazil's history.
Witnesses said he entered the school armed with two pistols and an ammunition belt, shooting at students and repeatedly yelling: "I'm going to kill you all!"
Elias da Silva paced outside a hospital hours after the shooting, waiting for news of his nephew, a 14-year-old boy who slipped on a pool of blood and twisted his ankle as he fled the school pulling along a friend during a moment when the gunman stopped to reload. His nephew escaped, but the girl was shot in the back and died, the uncle said.
"I asked God for him to come out alive and he did," Silva said. "He came out running and still thought to try to save his friend. This is going to be difficult for him to understand."
The motive for the attack wasn't known, but authorities said the shooter left a rambling and mostly incoherent letter at the scene indicating he wanted to kill himself.
The letter also explained in detail how Oliveira wanted his corpse to be cared for - bathed and wrapped in a white sheet that he left in a bag in the first room where he said he would start shooting. The letter also states that the gunman should not be touched by anyone who is "impure" unless they wear gloves.
"If possible I want to be buried next to my mother. A follower of God must visit my grave at least once. He must pray before my grave and ask God to forgive me for what I have done," read the letter, which was posted on the Globo television network's website.
Edmar Peixoto, the deputy mayor of western Rio, said the letter also stated the gunman had the AIDS virus.
Oliveira's neighbors told the newspaper Jornal do Brasil they couldn't believe the quiet young man who kept his head down and stayed out of trouble was responsible for so much bloodshed.
"He was never violent; he didn't get in trouble, throw stones, or fight in the streets," said Edna de Lira Ferreira, 55. "He was just quiet, and we respected the way he was. He just stayed in his room, in front of the computer."
Oliveira had been a Jehovah's Witness, like his adoptive parents and their other five children, Ferreira said.
Another neighbor, Elma Pedrosa, remembered Oliveira as an unusual youth who looked away when he passed acquaintances rather than greet them.
"He was anti-social, but he never demonstrated any violent tendencies," she said.
When Oliveira entered the school Thursday, he told staff members he was there to give a lecture, Rio Police Chief Martha Rocha said. Shortly afterward, he opened fire.
The gunman had no criminal history, Rocha added at a news conference.
Rio is a city rife with drug-gang violence in its vast slums, but school shootings are rare.
"What happened in Rio is without a doubt the worst incident of its kind to have taken place in Brazil," said Guaracy Mingardi, a crime and public safety expert at the University of Sao Paulo.
Police were alerted to the shooting when two young boys, at least one with a gunshot wound, ran up to two officers on patrol about two blocks away. The officers sprinted to the school and at least one quickly located the gunman on the second floor and traded shots with him.
"He saw me and aimed a gun at me," officer Marcio Alves said. "I shot him in the legs, he fell down the stairs and then shot himself in the head."
Rio Mayor Eduardo Paes said life at the four-story, pastel yellow and green school was turned into a "hellish nightmare."
"This day would have been so much worse if it weren't for the hero policeman," Paes told reporters at the school.
Associated Press writers Juliana Barbassa in Rio, Bradley Brooks, Stan Lehman, Tales Azzoni in Sao Paulo and APTN producer Ana Pereira contributed to this report.