sweden school
The killer posed for this picture before going on the rampage AFP

Police have confirmed a masked swordsman who killed two people at a Swedish school was motivated by racial hatred. Detectives said that evidence collected, including witness statements describing his behaviour at the scene, strongly suggested the 21-year-old attacker selected his victims on the base of ethnicity.

"All together, this gives a picture that the perpetrator had a racist motive when he committed the crimes," police said in a statement.

The attack targeted the Kronan school, in the western industrial town of Trollhattan. The institute serves the town's large immigrant community, with a majority of students said to be from foreign backgrounds.

The killer, who has not been named by authorities, was shot dead by responding security forces. He has been identified by Swedish media as local man Anton Lundin-Petterson. His social media profile revealed he was interested in far-right groups and had "liked" videos glorifying Nazi Germany.

He entered the school on the morning of 22 October brandishing a sword and wearing a military-style helmet and a black mask. The attire was described as similar to that of Star Wars villain Darth Vader.

Students initially thought he was playing a Halloween prank, with some posing for pictures with him. Then the attacker suddenly stabbed a teacher who asked him to leave because he was scaring some of the school's 400 pupils.

The 41-year-old teacher died of his wounds. Three students were also stabbed, including a17-year-old who was killed. The two students, who survived, aged 11 and 15, were taken in critical conditions to a local hospital.