Police chief Niclas Hallgren said they had based their conclusion on what was found at the killer’s apartment and “his behavior during the act”.
According to media reports, the 21-year-old attacker had far-right sympathies.
Armed with a sword and wearing a helmet and mask, the man stormed a school in Trollhattan, near Gothenburg, before being shot dead by police.
“We can confirm that this was a racially motivated hate crime partially because the man chose his victims based on the color of their skin,” Niclas Hallgren told Swedish Radio.
The helmet he wore was similar to German World War Two soldiers’ helmets.
He was seen posing for a photograph with students, who thought he was dressed for Halloween, before going from classroom to classroom at the Kronan School.
A teacher and 17-year-old boy died from stab wounds, while another male student, 15, and 41-year-old teacher remain in serious condition in hospital.
The attacker’s name has not yet been released by police, though they say he was local to Trollhattan. He did not have a criminal record, police say.
However, the Swedish daily Expressen and other Swedish media named him as Anton Lundin Pettersson, aged 21.
The young man had allegedly joined a campaign to push for a referendum on whether Sweden should continue accepting migrants.
Sweden has reacted with shock to the killings. Before visiting the scene of the attack, Swedish PM Stefan Lofven said it was a “black day” for the country.
“School is supposed to be the place for learning, play and curiosity and friendship and therefore this is a tragedy that affects the whole country,” Stefan Lofven told reporters.
King Carl Gustaf of Sweden said he was “in shock” and that he had learned of the events in Trollhattan “with great dismay and sorrow”.
Dozens of people gathered outside the school building on October 22 to pay their respects to the victims and place flowers and candles on the ground.
Some residents of the town who were holding a vigil held up posters that read “why kill?”
Swedish media reports say the suspect’s accounts on Facebook and YouTube suggest he had an interest in Hitler and Nazi Germany, as well as hostility to Islam and immigration.
“He was a loner. He played video games, lived in his own world,” a former classmate told Expressen.
Eyewitnesses described scenes of chaos, with the attacker knocking on the doors of at least two classrooms and attacking two male students who opened them. One of the boys later succumbed to his injuries.
None of the victims have been identified by police.
Police were alerted to the attack at around 10:10 local time on October 22, and later gunned down the attacker in the hallway outside a classroom.
The Kronan school has about 400 students aged between six and 15, including many children of immigrants.
Trollhattan is an industrial town in west Sweden, located about 50 miles north of Gothenburg, the nation’s second largest city.
School attacks are rare in Sweden – with just one incident on record in the past 20 years, in which one student was shot dead.
At least 158 people have died in Spain's worst flooding disaster in generations. On October…
Google has been fined two undecillion (a two followed by 36 zeroes) roubles by a…
Embarking on a home remodel is an exciting journey, promising enhanced comfort, increased property value,…
The US presidential candidates continued to campaign across key swing states on October 20. Footage…
Elon Musk has said he will give away $1 million a day to a registered…
India and Canada have decided to expel their top envoys along with other diplomats as…