(CNN) The attack on a school in Sweden in which a student and a teacher were killed was motivated by racism, police have told CNN.

A police spokeswoman said the conclusion was reached because of "the way (the suspect) dressed and behaved but also how he picked his victims, who had a specific ethnic background." Items found in the man's home contributed to the determination of motive, she said.

Two of the victims were immigrants, Swedish police said Friday. One of the people killed was a male from Somalia born in 1998. A male immigrant born in 2000 was among those wounded, but police did not disclose his nationality.

Police had previously said they were looking into the "attacker's possible links to right-wing organizations."

The man, masked and wielding a sword or knife, killed two people Thursday morning at a school in Trollhattan before police shot him, authorities said. He died at a hospital.

Two others -- a teacher and student -- were wounded in the attack on the Kronan primary and middle school. The injured were reported to be in serious condition at the hospital in Trollhattan, hospital officials said.

"This is a dark day for Sweden," Prime Minister Stefan Lofven said. "My thoughts go out to the victims and their families, pupils and staff, and the entire community that has been affected. There are no words to describe what they are going through right now."

Posing with students before attack?

AFP received this photo purportedly showing a masked man with students.

An unidentified student gave Agence France-Presse a photo purportedly showing a masked man -- allegedly the person who would commit the attack -- posing with students at the school Thursday morning, AFP reported. The photo shows the man wearing a helmet and holding what appears to be a blade.

The student told AFP the photo was taken before the attack; the precise timing of the photo was not immediately known.

A student identified as Edona told Sweden's TV4 that students first thought the man was playing a Halloween joke.

He was "walking like a soldier, kind of, with a sword in his hand," the student said.

But when the man began attacking, the students reacted with horror.

"We were pretty shocked, all of us," Edona said.

Police: 'We fired two shots'

Police received an alarm call shortly after 10 a.m. "that a masked man in his 20s had entered the school ... (and was) carrying knife-like weapons in his hands, attacking students and adults at the school," police spokesman Thomas Fuxborg said. "We fired two shots, one of which hit and incapacitated the man so that we could arrest him."

Fuxborg said officers found an injured man outside the school and a dead man just inside.

On the second floor, officers found the two students who had been wounded in the attack, Fuxborg said.

Police evacuated the school.

Police spokeswoman Jenny Widen said the two people killed were both male -- a teaching assistant born in 1995 and a student born in 1998.

The suspect was born in 1994, she said.

'Tracks of blood'

Thord Haraldsson, police superintendent in Vastra Gotaland County, told reporters the assailant first attacked a teacher outside the school.

"Then he enters the building and meets another one that he attacks," Haraldsson said. "... Then he systematically searches the school building. We can follow tracks of blood in the premises.

"He walks to the classrooms, knocks on the door, and when (a) pupil opens the door, he is attacked ... stabbed at the spot.

"This happens in two different classrooms, and one of (the attacked students) is now deceased."

Trollhattan is about 420 kilometers (260 miles) west-southwest of Stockholm, the capital.

Growing intolerance?

The attack prompted many to question how such a violent attack could happen in a country known for its liberal tolerance.

Sweden has a population of more than 9 million and accepted at least 80,000 asylum seekers last year. In line with its traditional liberal immigration policies, Sweden takes in the most refugees per capita, by far, of any EU nation. Today, about one in five Swedes has a foreign background.

The government provides generous benefits to asylum seekers. They are given housing and a living allowance. They're also allowed to work immediately -- a policy that sets Sweden apart from many other countries.

But there is a dark side to this: Some connect the country's immigration policies to a growing intolerance to foreigners and outright racism in some segments of Swedish society. There are also worrying signs that Sweden's model of integration is not working as well as was hoped.

The number of hate crimes in Sweden rose 14% from 2013 to 2014, according to the Swedish National Council on Crime Prevention

There were more than 4,000 racist attacks last year. Nearly a quarter of those specifically targeted individuals of African ethnicity, even though less than 2% of Swedes identify as Afro-Swedish.

Neighborhoods in cities such as Malmo have controversially been labeled as "ghettos" by Swedish media, which has drawn a connection between the large immigrant populations and rising crime rates and unemployment. Malmo, in particular, has suffered from a series of grenade attacks that, police say, are driven by gang warfare linked to immigrant communities.

According to the OECD, Sweden has one of the largest employment gaps between foreign-born and native Swedes. The latest data show that while only 6.5% of the native labor force is unemployed, that number is more than double for foreign-born Swedes at 16.1%.

The public has reacted to these trends by shifting further to the right politically. In 2014, the Sweden Democrats campaigned on a staunchly anti-immigration platform. They claimed 13% of the vote, becoming Sweden's third largest political party.

Now, Sweden is once again taking in a growing number of refugees, this time from Syria and Iraq. But amid the influx, the attack in Trollhatten is likely to heighten fears of more racist attacks, even in a country as welcoming as Sweden.