A 13-year-old Spanish boy armed with a crossbow and a machete killed a substitute teacher and wounded four people at his school in Barcelona Monday, police said.

The unidentified boy was detained by police as a suspect after the attack that also saw two other teachers and two students injured. Authorities said he will not face criminal charges because he is under age 14.

The attack, which took place just after 9.30 a.m., sowed terror in the high school in a working class neighborhood of Spain's second-largest city. School attacks are extremely rare in Spain.

"We were just starting the class and suddenly we heard screams," said student Gemma Jarque. "So we shut ourselves inside our classroom in order to be safe."

A regional police spokeswoman said the boy had a crossbow and a machete but she was unable to say which weapon caused the man's death.

She said the investigation was being carried out under a secrecy order and she had no further details.

She spoke on condition of anonymity because of police regulations that prevented her from being identified by name.

The boy was taken to a hospital for a psychiatric examination, said Jose Miguel Company, a spokesman for the Barcelona prosecutor's office.

"He was very disturbed and saying strange and incoherent things," said Company, who added that the examination is aimed at determining whether the boy has psychiatric problems or whether he was faking them.

Authorities did not disclose details of how the attack played out, but Jarque said she and others hid in her classroom after hearing the screams, and left along with other students only after a fire alarm sounded.

"We saw the teacher lying on the floor in a pool of blood," she said.

Another student, Paula Amayuelas, said she knew the suspect and that he "didn't have problems but he was kind of a loner. Other students would pick on him."

The two wounded students and one of the injured teachers were taken to Barcelona hospitals for treatment while the other injured teacher was treated at the scene and did not need hospitalization.

Parents and students gathered in stunned silence outside the school for students ages 12-16, hugging each other. Students said the teacher killed was a substitute working at the school for about a week.

Police in Barcelona did not identify the suspect because of his age.

In Spain, children under age 14 are not held legally responsible for crimes and cannot be jailed or placed in juvenile detention centers.

They can be sent to mental health institutions, said a spokesman for Spain's Justice Ministry who spoke on condition of anonymity because of ministry policy.

A national police spokesman could not recall any fatal school attacks in the country's recent history.

Spain did avert an attempt in 2012 by a 21-year-old Spanish man who allegedly wanted to imitate the attack at Columbine High School in Colorado that killed 12 students and one teacher.

A spokesman for regional police said it was too early to determine whether Monday's attack was an attempt to copy the Columbine attack, which took place 16 years ago to the day.