Swedish authorities said Friday that the masked attacker who fatally stabbed a teacher and a student at a school was motivated by racism.

Police said they were classifying Thursday's attack in the industrial town of Trollhatan as a hate crime based on evidence discovered while searching the attacker's home, as well as the way he dressed, his behavior at the scene and the way he selected his victims.

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

The 21-year-old assailant, identified in Swedish media reports as Anton Lundin Pettersson, posed for pictures with students while wearing a military-style helmet and a black mask before beginning his deadly rampage. Authorities said he roamed the halls of the school, knocking on the doors of two classrooms and slashing those who opened them.

Panicked students fled the school, as police and ambulances rushed in. They found a dead male teacher and three people seriously wounded — two boys, aged 11 and 15, and another male teacher. Local newspaper GT, citing relatives, identified the deceased victims as 20-year-old Lavin Eskandar, a mentor at the school, and Ahmed Hassan, a 15-year-old student. The paper reported that Hassan was born in Somalia and moved with his family to Sweden in 2012. GT also reported that the injured boy, who has not been identified, had arrived in Sweden from Syria nine months ago.

Officers fired two shots, hitting the attacker with a bullet in the lower chest, and he died later at a hospital.

The attack stunned Sweden, where violent crime is relatively rare, though there has been a recent spate of arson attacks on asylum centers in the south of the country as the influx of refugees from Asia, Africa, and the Middle East has surged. Immigration officials estimate that some 190,000 foreigners will arrive this year, second only to Germany in western Europe.

Approximately 400 students attend the school, whose pupils range in age from preschool to high school. By end of 2013, 10,373 people in Trollhattan, a town of 56,000, were foreign-born, according to official figures, with most coming from the Middle East, the Balkans and Ethiopia. A majority of the students at Kronan are foreign-born.

The Swedish tabloid Aftonbladet reported that Pettersson had lived in Trollhattan for his entire life, but attended a different school from the one he attacked. A high school friend of Pettersson's told the paper that he almost always wore black or camouflage-patterned clothes. The paper also reported that after Pettersson left school, he cut off his hair and liked social media pages that celebrated Adolf Hitler and Nazi Germany. He also reportedly signed a Facebook petition calling for a halt to all immigration into Sweden.

Aftonbladet also reported that Pettersson had no criminal record before the attack and was not known to the police. One investigator was quoted as telling Dagens Nyheter, "He's a blank paper for us." Neighbors approached by the paper described him as a pleasant person who often greeted them with a smile.

Sweden's last school attack was in 1961, when a 17-year-old man opened fire at a school dance hall in the southwestern part of the country, wounding seven students, one of whom died later. Violent crime is rare in the country, which has strict gun-control laws. In 2013, there were 87 homicides reported in Sweden, a country of some 10 million people.

The Associated Press contributed to this report.

Click for more from Aftonbladet.