He first shot teachers at his former school, a public elementary and secondary school, killing two others and wounding nine.
The attacker then went to a private school on the same street, where he killed a teenage girl and wounded two people, authorities said.
The detained teenager showed the governor of Espirito Santo, Renato Casagrande.
“He studied at (the first) school until June, a minor of 16 years. Then his circle of relatives moved him to another school. We have data that he is in psychiatric treatment,” Casagrande said at a press conference.
Two firearms were used in the attack through the teenager, who is the son of an army policeman. Both weapons were registered in his father’s name.
Security camera footage released by Brazilian media showed the gunman running into the school, running into the hallways with a semi-automatic weapon and firing. Police are investigating any possible links to extremist teams because he had a swastika on his uniform.
The lives of some of the injured in danger, the governor said, declaring 3 days of mourning in the state.
School shootings are rare in Brazil, but have seen an uptick in years.
Twelve young men were killed in 2011, when a guy opened fire at his former number one school in Realengo, a suburb of Rio de Janeiro, and then killed himself.
In 2019, two former students shot dead eight other people at a major school in Suzano, on the outskirts of São Paulo, and then also committed suicide.
President-elect Luiz Inacio Lula da Silva the shooting an “absurd tragedy. “
Lula, who was president from 2003 to 2010, will take office on Jan. 1 after defeating far-right President Jair Bolsonaro in last month’s election.
He harshly criticized Bolsonaro’s other gun laws.