The injured were mostly left with gunshot wounds to the chest and head.
The gunman, named as former pupil Wellington Menezes de Oliveira, later killed himself. He entered a classroom in the Tasso de Silveira public school armed with two revolvers and began shooting at the children.
The incident began at about 8.30am local time (12.30pm in Britain).
Witnesses said police responded quickly and traded fire.
It is understood Oliveira, 24, was shot in the leg by police before he turned the gun on himself.
Local media reports said the former pupil had told school officials he was there to make a speech, before pulling out two guns and opening fire on students.
Terrified parents, on hearing the news, rushed to the scene for information about their children.
TV images showed more than 100 people gathered outside the school for children aged 10 to 15.
Local police commander Djalma Beltrame said the gunman left a letter at the scene indicating that he wanted to kill himself.
However it did not give a clear motive for the shooting.
Television images showed shocked parents crying and screaming as they waiting outside for information about their children.
TV also showed three helicopters landing on a football field next to the school and then ferrying the wounded to nearby hospitals.
The incident is not being linked to the city’s drug violence.
Government officials have had some success in tackling the notorious drug gangs that control vast swathes of the poverty-stricken slums that surround the city but violent crime remains a problem for the authorities.
Police have increased patrols in some of the poorer neighborhoods in hopes of tightening security in advance of the 2014 World Cup soccer championship and the 2016 Olympic Games.