The guard sprayed them with alcohol before setting them on fire, according to one news account. Four children and a teacher died, in addition to the guard. Military police said, the man also set himself alight at the building in the remote town of Janauba, Minas Gerais state.
Janauba's mayor has decreed seven days of mourning.
About 50 people were sent to hospital with injuries, said Bruno Ataide Santos, director of the local hospital.
Hours later, 10 people remained hospitalised in serious condition.
Santos, who burned himself after attack, died in hospital where he was removed.More news: Edmonton terror attacks: Abdulahi Sharif charged with attempted murder
More news: National Basketball Association changes All-Star Game format; captains will pick teams
More news: The Nobel Prize for Physics was Awarded to Gravitational Waves Observers
Officials said that the accused security guard, who worked as a night watchman at the school since 2008, was suffering from depression.
While Jane Kelly, the mother of Juan Miguel Soares expressed grief, "I woke him up early to bring him here and when I saw him again he was dead in the hospital".
They also revealed they have opened a line of inquiry into Mr dos santos who is believed to have been suffering from mental health issues, saying they have searched his home and questioned his family and close friends in order to determine his motives for carrying out the devastating attack. "As the children were bigger a lot of them were able to escape".
"I deeply regret this tragedy with the children in Janaúba (MG). I want to express my sympathy to the families".
Mr Temer said that, as the father of a school-age child, he understood this must be an extremely painful loss for the parents.