A masked swordsman who killed a teaching assistant and a boy and wounded two others sought out his victims, all with immigrant backgrounds, by skin colour in an attack that has fuelled fears that a big refugee influx is polarising Swedish public opinion.

MUST WATCH: [VIDEO] Masked man with sword kills two at Swedish school, shot dead by police

The 21-year-old assailant strode on Thursday through a school in Trollhattan, an industrial town in western Sweden with a large immigrant population, stabbing his victims with the sword before being shot dead by police.

You can't blame asylum policy because we have a madman who murders children
Security footage from the school showed the killer marching through school corridors and stopping to talk to light-skinned students, police said.

"Everything points to this being a hate crime," lead investigator Thord Haraldsson told a news conference. "He selected his victims and attacked the dark-skinned ones and left the light-skinned ones alone."

Interior Minister Anders Ygeman said record numbers of refugees had fuelled racism among a small segment of society.

"We will have to ask ourselves several questions about how society is developing, about polarisation and mobilise all good forces against this racist violence," Ygeman told TV4.

The killings happened on the same day that the government announced up to 190,000 refugees, a record number, could arrive in Sweden this year.

The government and opposition agreed on Friday to restrict Sweden's generous immigration policies, worried that its resources have been stretched to their limit with tents being prepared to shelter thousands of new arrivals.

Ygeman defended the government's liberal asylum-seeking policies, under which Sweden had accepted more refugees per capita than any other European country in recent years. Over the decades, Sweden has welcomed refugees ranging from Vietnam war draft dodgers in the 1960s to Gulf War refugees in the 1990s.

"You can't blame asylum policy because we have a madman who murders children," Ygeman said.

"WE WERE TERRIFIED"

Swedish media said one of the dead, a 17-year old pupil at the school, had come to Sweden from Somalia three years ago. A 15-year old, recovering in hospital from stab wounds, had recently arrived from Syria.

Police said they had found a "a sort of suicide note" which clearly pointed to racist motives and showed the assailant had acted alone.

In a photo taken after the killer had stabbed at least one person, he posed in a corridor with pupils who thought his cape, mask and World War Two-type helmet were part of a Halloween prank. Moments later he stabbed a teacher who approached him.

"Then he chased us through the school, we were terrified," one girl told Aftonbladet.

The suspected killer's social media accounts showed likes for pro-Nazi video clips as well as an anti-immigration campaign, according to local media.

"We have never felt afraid in Sweden," daily Aftonbladet quoted the mother of the injured boy saying.

School attacks are almost unheard of in Sweden - the last incident was near the city of Gothenburg in 1961 when one student was shot dead and six others were injured - and violent crime in general is rare.

Polls show most Swedes welcome refugees. But tensions have been rising.

A number of asylum centres have been attacked in the past week.

Police were forced to improve security at centres in August after the murder of a Swedish man and woman by a refugee at an IKEA store in the city of Vasteras. The refugee had been denied asylum shortly before the attack.

MUST WATCH: [VIDEO] Stabbing spree at an IKEA in Sweden leaves two dead

The centre-left government and centre-right opposition reached a deal to tighten immigration rules, introducing three-year temporary residence permits, with exemptions for some, including families with children and unaccompanied minors.

Previously, asylum seekers were granted permanent residency.

"The situation is unsustainable and we are at the limit of what we can deal with," Migration Minister Morgan Johansson told a news conference.

The anti-immigrant Sweden Democrats party has seen its popularity soar, with polls showing it would get around 20 percent of the vote now, up from around 13 percent in a national election last year.

The party plans an advertising campaign in foreign media aiming to warn off asylum seekers.