A 13-year-old boy has been arrested in Spain for allegedly shooting a teacher dead with a crossbow at his school.

The unnamed pupil opened fire with the weapon at the Joan Fuster school in Barcelona at around 9.20am local time and unconfirmed reports claimed he was also armed with a machete, BB gun and material to make molotov cocktails.

Two students and two teachers were wounded and the victims were taken to hospital while the school was shut down and traumatised children were taken away for counselling.

Witnesses claimed the boy knocked on a classroom door and immediately attacked a languages teacher with the crossbow as it opened, before stabbing her 13-year-old daughter.

The student reportedly told the screaming pupils in the class to “calm down”, adding “I am not interested in you”, La Vanguardia reported.

Hearing the uproar, another teacher ran into the room to help his colleague and was shot in the abdomen, El Pais reported. He was pronounced dead at the scene.

The man was said to be working as a substitute social sciences teacher at the school in the Sant Andreu district of Barcelona.

One student said the attacker targeted one of her friends but they managed to escape.

“The boy came into our class with a knife and wanted to attack a friend of mine. But he didn't manage to, he left, and we had a chance to run away,” the pupil told Reuters TV.

Children barricaded themselves into nearby classrooms and reportedly only evacuated when a fire alarm was set off, unaware of what had occurrred.

“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.

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

Pupils who witnessed the rampage are being given counselling after being interviewed by police (AP)

Another pupil told El Mundo newspaper that the boy had previously threatened to murder teachers before killing himself.

Classmates claimed there was a collection of weapons at his home and the teenager aspired to join the military, telling La Vanguardia that he wrote “blacklists” of pupils and teachers he disliked.

"He didn't have problems but he was kind of a loner," said Paula Amayuelas, who knows the suspect. "Other students would pick on him."

A spokesperson for the Mossos d’Esquadra police force said two teachers and two students were wounded in the rampage.

People stand behind a police cordon outside the school in Barcelona following the attack (AP)

They were taken to hospital and one victim, a female teacher, has already been discharged.

Xavier Trias, the mayor of Barcelona, said he was “appalled” by the tragedy and was visiting the scene.

“All my support to the educational community, teachers, parents, students and staff at the Joan Fuster Institute,” he wrote on Twitter.

The age of criminal responsibility in Spain is 14, meaning that the boy cannot be arrested or charged with a crime. He has been taken to a psychiatric facility and is reportedly being held for assessment.

Jose Miguel Company, a spokesperson for the Barcelona prosecutor's office, said: "He was very disturbed and saying strange and incoherent things."

The attack comes on the anniversary of the 1999 Columbine High School massacre in the US, in which 12 students died.