SAO PAULO -- A 13-year-old student in Brazil's biggest city fatally stabbed a 71-year-old teacher and wounded three teachers and two fellow students Monday in a knife attack at a public school, state officials said.

The five wounded victims from the Thomazia Montoro school in Sao Paulo were in hospital in stable condition. The suspected attacker was detained and the state's military police is investigating.

鈥淥ur efforts are concentrated on helping the wounded and comforting the family members,鈥 Gov. Tarcisio de Freitas wrote on social media.

A student who spoke to reporters alongside his mother outside the school said the attacker had insulted another student last week, and that the female teacher he fatally stabbed had tried to settle the conflict.

The attacker had called the other student a 鈥渞at,鈥 and 鈥渢he other one did not like it, and they began fighting,鈥 said Gabriel Livramento, 13, who is in the same class as the suspect. He added that the attacker did not like the way the teacher had intervened and had said he would do something about it.

The attacker entered class Monday wearing a skull mask and stabbed the teacher from behind, hitting her head and back, Livramento said. The entire class then started running, he said.

The boy had searched for ways to obtain a firearm on the internet, authorities said in an afternoon press conference. He had recently been transferred from another school.

Bridi reported from Brasilia.