Witnesses said panic broke out as the gunman dressed in black and carrying a large bag entered the school in Kauhajoki, 180 miles northwest of Helsinki, and started firing in a classroom where students were taking an exam. The shootings began just before 11 a.m. local time (0800GMT), as about 150 students were at the Kauhajoki School of Hospitality.
"I heard several dozen rounds of shots, in other words it was an automatic pistol," school janitor Jukka Forsberg told Finnish broadcaster YLE. "I saw some female students who were wailing and moaning and one managed to escape out the back door."
The gunman had been questioned Monday by police about YouTube postings in which he is seen firing a handgun, but was released because there was no legal reason to hold him, Interior Minister Anne Holmlund said.
It was Finland's second school massacre in less than a year and the two attacks had eerie similarities. Both gunman posted violent clips on YouTube prior to the massacres, both were fascinated by the 1999 Columbine school shootings in Colorado, both attacked their own school and both died after shooting themselves in the head.
Kauhajoki Mayor Antti Rantakokko said nine victims were killed at first. The gunman was taken to a hospital in Tampere, about two hours away, along with a female victim he had shot in the head, and hospital officials said later that both had died.
Finnish tabloid Ilta-Sanomat said police identified the gunman as Matti Juhani Saari, a 22-year-old student.
"We have experienced a tragic day," Prime Minister Matti Vanhanen said as he expressed condolences to the families of the victims and declared Wednesday a day of mourning.
Finnish authorities did not confirm exactly what YouTube clips were linked to the shooter. But in one YouTube clip, a young man wearing a leather jacket fires several shots in rapid succession with a handgun at what appears to be a shooting range.
The posting was made five days before the shooting and the location was given as Kauhajoki -- the same town as Tuesday's shooting. The posting included a message saying: "Whole life is war and whole life is pain. And you will fight alone in your personal war."
The person who posted the clip identified himself as a 22-year-old with the name "Mr. Saari." He also posted three other clips of himself firing a handgun in the past three weeks.
Clips from the 1999 Columbine school shootings in Colorado were listed among his favorite videos.
Last November, another gunman killed eight people and himself at a school in southern Finland, an attack that triggered a fierce debate about gun laws in this Nordic nation with deep-rooted hunting traditions in the sub-Arctic wilderness.
Pekka-Eric Auvinen, described by police as a bullied 18-year-old outcast, opened fire at his high school in southern Finland on Nov. 7, killing six students, a school nurse and the principal before ending his own life.
Finnish investigators have said Auvinen left a suicide note for his family and foreshadowed his attack in YouTube postings.
With 1.6 million firearms in private hands, Finland is an anomaly in Europe, lagging behind only the United States and Yemen in civilian gun ownership, studies show.
After Auvinen's rampage, the government said it would raise the minimum age for buying guns from 15 to 18, but insisted there was no need for sweeping changes to Finland's gun laws.