TROLLHATTAN, Sweden (AP) — It was a racially motivated, carefully planned rampage, police say. The 21-year-old masked man marched through a Swedish school with a sword and a knife, methodically selecting his victims. Within minutes, two people had been stabbed to death and two others seriously wounded before the attacker was fatally shot by police.

Swedish police on Friday labeled Thursday’s stabbing attack in Trollhattan a hate crime based on discoveries they made when searching the man’s home, the way he dressed, his behavior at the scene and the way he selected his victims.

The southern industrial town has a large immigrant population among its 56,000 people and most students at Kronan school, where the attack took place, are foreign-born.

“All together, this gives a picture that the perpetrator had a racist motive when he committed the crimes at Kronan school,” Trollhattan police said in a statement. “His way of marching points to Nazism.”

Police have not identified the attacker, a local man who died in the hospital of his gunshot wound later Thursday.

Senior police officer Niclas Hallgren told a news conference that surveillance videos showed him roaming with a sword and a sharp knife Thursday morning inside the school.

On the video, police noticed how he “selects his victims. And those with dark skin were attacked,” investigator Thord Haraldsson told reporters. “The victims were dark-skinned.”

Evidence appears to show that he acted alone, Haraldsson said, adding that police found “a kind of suicide note” in his apartment. In it, the attacker “tells us by that letter that he considers this his final act,” Hallgren said.

The sword’s sheath was found inside a car parked near the school, Haraldsson said.

None of the victims have been identified by authorities. However, local newspaper GT cited relatives as saying those who died were 20-year-old Lavin Eskandar, a mentor at the school, and Ahmed Hassan, a 15-year-old student.

A few hundred people held an anti-racism protest Friday outside the school, whose roughly 400 pupils range from pre-school to high school. “No to racism, no to hatred,” one poster read. Signs in Swedish and Arabic urged people to respect the mourning.

“We do not have all facts yet, but we know innocent people have died. Maybe because of the distorted debate in the society,” Imam Abdi Rizak Wabari said during Friday prayers at a nearby mosque.

Once Sweden’s busy industrial city, a center for heavy industries and car production, Trollhattan has been struggling with unemployment for years. It now has Sweden’s highest jobless rate — 14.1 percent in 2014 against 8 percent for the whole country. In addition, the city’s rate of people with higher education is 20.9 percent, below the national average of 25.1 percent.

The attack stunned Sweden, where violent crime is relatively rare, although there has been a spate of arson attacks on asylum centers in recent weeks as an influx of refugees has surged. Immigration officials estimate some 190,000 asylum-seekers will arrive this year, second only to Germany in Western Europe.

“This is a black day for Sweden,” Prime Minister Stefan Lofven said of the country’s deadliest-ever school attack. “It is a tragedy that hits the entire country.”

Surveillance videos authenticated by police show that the assailant posed for photos with some students before beginning his deadly rampage. Several students thought the attacker was playing a Halloween prank.

Police said the assailant entered the school through a cafe in its lobby that is open to the public. He stabbed two victims, then knocked on two classroom doors and stabbed two more victims.

Panicked students fled the school as police and ambulances rushed in. Authorities found a dead male teacher and three people seriously wounded — two boys and another male teacher. All the wounded had surgery but one of the students later died.

The wounded student’s condition had improved Friday and he was considered stable, a spokeswoman for the Norra Alvsborgs Lanssjukhus hospital said, and the 41-year-old teacher was in “serious but stable” condition.

Sweden’s last school attack was in 1961, when a 17-year-old opened fire at a school dance in the southwest, wounding seven students, one of whom died later.

___

Jan M. Olsen in Copenhagen contributed to this report.

___

This story has corrected the spelling of the school’s name to Kronan.