Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A masked man wielding a sword stabbed a teacher and a student to death before he was shot by police in western Sweden, officials said Thursday.

The 21-year-old attacker, who was not immediately named, later died at the hospital, police in Trollhattan said at a news conference. Two others — another teacher and student — were badly injured in the rampage in a cafe area at the Kronan School.

Authorities initially said four students and one teacher had been hurt. But Thomas Fuxborg, the police spokesman for Vastra Gotland county, later confirmed that one adult man was found dead at the scene along with two injured students and an injured adult.

"We just ran."

He told Swedish television the school's employees had called police and responding officers encountered an armed "masked man."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"The attacker ... went on the attack against us," Fuxborg said. "We fired two shots — one shot hit him."

Fuxborg did not provide further details on the wounded or identify the attacker, saying only that the assailant was not a student at the school.

The hospital in Trollhattan said it had received four severely injured patients: a teacher, two students — ages 11 and 15 — and the suspected attacker. One of the students, along with the attacker, were later pronounced dead.

Police cordoned off an area after a masked man attacked people with a sword at a school in Trollhattan, western Sweden, on Thursday. TT NEWS AGENCY / Reuters

Earlier, police told NBC News that there was no information to suggest the attack was terrorism-related but noted that officials have "a lot of questions" and had not yet established the possible motive.

Ambulances and police vehicles were on the scene outside the school’s red building following the attack.

One eighth grade student at the school said he initially thought the attacker was pulling a prank — but then he saw a teacher get stabbed.

"So we just ran," he told Swedish television.

The Kronan School has students between the ages of around 6 and 15, according to police.

Trollhattan is a small town about 45 miles miles north of Sweden's second-largest city, Gothenburg.