Media reports suggest the 21-year-old attacker had far-right sympathies.
Armed with a sword and wearing a helmet and mask, he stormed a school in Trollhattan, near Gothenburg, before being shot dead by police.
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.
Sweden has reacted with shock to the killings. Before visiting the scene of the attack, Swedish Prime Minister 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," Mr Lofven told reporters.
King Carl Gustaf 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 Thursday evening 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?"
More about: