An 18-year-old gunman opened fire at his high school in this placid town in southern Finland on Wednesday, killing seven other students and the principal before mortally wounding himself in a rampage that stunned a nation where gun crime is rare.

Police were analyzing YouTube postings that appeared to anticipate the massacre, including clips in which a young man calls for revolution and apparently prepares for the attack by test firing a semiautomatic handgun.

Investigators said the gunman, who was not identified, shot himself in the head after the shooting spree at Jokela High School in Tuusula, some 30 miles north of the capital, Helsinki. He died later at Toolo Hospital in Helsinki.

The teen killed five boys, two girls and the female principal with a .22-caliber pistol, police said. Officials said one person was wounded by a bullet and about a dozen others suffered cuts and other injuries while fleeing the school. Officials said more than 400 students ages 12 through 18 were enrolled.

Witnesses described a scene of mayhem at the school in this leafy lakeside community, saying the shooter prowled the building looking for victims while shouting slogans for "revolution."

Police Chief Matti Tohkanen said the gunman didn't have a previous criminal record. "He was from an ordinary family," Tohkanen said. He said the teen belonged to a gun club and had gotten a license for the pistol Oct. 19.

Gun ownership is fairly common in Finland by European standards, but deadly shootings are rare. Finnish media reported that a school shooting in 1989 involved a 14-year-old boy who killed two other students apparently for teasing him.

Investigators were searching for connections to the shooter and a possible motive in YouTube postings that appeared to reveal plans for Wednesday's deadly attack.

One video, titled "Jokela High School Massacre," showed a picture of what appeared to be the Jokela school and two photos of a young man holding a handgun. The person who posted the video was identified in the user profile as an 18-year-old man from Finland. The posting was later removed.

The profile contained a text calling for a "revolution against the system."

Another video clip showed a young man clad in a dark jacket loading a clip into a handgun and firing several shots at an apple placed on the ground in a wooded area. He smiled and waved to the camera at the end of the clip.

A third clip showed photos of what appeared to be same man posing with a gun and wearing a T-shirt with the text "Humanity is overrated."

Kim Kiuru, a teacher, said the principal announced over the public address system just before noon that all students should remain in their classrooms.

"After that I saw the gunman running with what appeared to be a small-caliber handgun in his hand through the doors toward me, after which I escaped to the corridor downstairs and ran in the opposite direction," Kiuru told reporters.

He said he saw a woman's body as he fled the building.

"Then my pupils shouted at me out of the windows to ask what they should do and I told them to jump out of the windows ... and all my pupils were saved," Kiuru said.

Terhi Vayrynen, a 17-year-old student, told The Associated Press that her brother Henri, 13, and his classmates had witnessed the assailant shoot the principal outside the school through their classroom windows.

She said the gunman then entered her brother's classroom shouting: "Revolution! Smash everything!"

When no one did anything, the attacker shot the television set and windows but did not fire at the youngsters, she said. Then he ran out and down the corridor.

Vivianna Korhonen, a student at the high school, told Finnish broadcaster YLE she feared for her life as news of the shooting spread through the building.

"We were terrified and afraid. We thought that we might die as he was still able to come to our classroom," she said. "We were informed all the time. We were calling our friends and asking for information."

Residents in Tuusula, a town of 34,000 people, said such attacks were unheard of in the area.

"Mostly nothing happens here, this is nice surroundings and not any criminals to talk of. This was a total surprise," said Reijo Pekka, whose son Arttu Siltala was at the school.

Students said the killer often wore the same clothes to school -- brown leather jacket, black trousers and checkered shirt -- and usually carried a briefcase.

Tuomas Hulkkonen, another student, said he knew the gunman well, adding that the teen had been acting strange lately.

"He withdrew into his shell. I had noticed a change in him just recently, and I thought that perhaps he was a bit depressed, or something, but I couldn't imagine that in reality he would do anything like this," Hulkkonen told Finnish TV broadcaster MTV3.

Experts warned that the shooting could inspire copycat attacks.

"An event like this in Finland might have an effect in the U.S.," said Christopher P. Lucas, a psychiatry professor at New York University.

He said YouTube provides a ready way for shooters to publicize their acts and provide some sort of justification.

Finnish Prime Minister Matti Vanhanen described the bloodshed as "extremely tragic" and declared Thursday a day of national mourning with flags to be flown half-staff.