A sword-wielding madman wearing a “Star Wars” mask killed a teacher and seriously injured at least four students and another teacher Thursday at a school in Sweden, according to reports.

The lunatic burst into the school in Trollhättan, north of Gothenburg, and began his maniacal attack early Thursday, the Daily Mail reported.

He began attacking responding cops, who quickly shot him. He was hospitalized in serious condition.

“One of my friends opened the door and there’s a man dressed in black with a ‘Star Wars’ mask and a large black sword,” a student told local TV.

The injured 11- and 15-year-old students and teacher were rushed to a hospital, where they underwent surgery for serious knife wounds.

Authorities have declined to confirm reports that the attacker, said to be in his 20s, is a former student.

Students locked themselves in closets and cupboards to avoid the attacker, who carried several weapons, including “at least one knife-like object,” a police official told the AP.

“When we first saw him, we thought it was a joke. He had a mask and black clothes and a long sword. There were students who wanted to go with him and hold the sword,” a student told local media, The Guardian reported.

A student said she managed to flee from the assailant.

“One of my classmates’ sisters called her to warn her that there was a murderer at the school. So we locked the door to the classroom, but our teacher was still outside in the corridor. We wanted to warn him, so a few of us went outside and then I saw the murderer, he was wearing a mask and had a sword,” the student told local media, The Guardian reported.

“Our teacher got stabbed. The murderer started chasing me, I ran into another classroom. If I had not run, I would have been murdered.”

Authorities said there was “a lot of confusion” at the Kronan school — with students and teachers still inside more than two hours after the attack, AFP reported.

Swedish media said the school held a meeting Thursday morning to address worries that the school, with a café for adults, was too open and lax in security, the AP reported.

Prime Minister Stefan Lofven was expected to visit the town later Thursday, the Swedish parliament’s Twitter account said.

Trollhättan, an industrial town of 57,000, is home to the former carmaker Saab, which filed for bankruptcy in 2012.

School attacks are rare in the country. In 1961, one person was killed and six others injured in an attack at a school in Kungalv, in southwestern Sweden.