HELSINKI  - A gunman opened fire at a crowded school and an office building in southern Finland on Friday before he was arrested, officials said, in what appeared to be a revenge attack on an ex-girlfriend. Police said one person was slightly wounded in the attack. The gunman fired six shots through the door of a locked classroom on the third floor of a secondary school in the town of Orivesi, as 14 pupils and a teacher cowered inside, police said. Jani Koskinen had reportedly knocked on the classroom door and thanks to the teacher's quick decision to lock the door and move all the pupils out of shooting range.

However police said the gunman had earlier fired shots at an office building about a kilometre (half a mile) from the school, slightly wounding one person in the arm.

"The shooter was the same in both cases," local police said in a statement.

Police would not comment on reports that Koskinen's 16-year-old ex-girlfriend Milla Lehtonen was inside the classroom he attacked, and that the man had been sought by police earlier this month when the girl, who had already broken up with him, briefly went missing.

According to commercial broadcaster MTV3, the man injured in the office building was the girl's father, who along with her mother had previously requested a restraining order against Koskinen.

"The shooter came to our office without saying anything. He asked our secretary to get me. I came, and the shooter came towards me with a gun in his hand," the man, whose name was not given, told the broadcaster.

"He shot immediately. It was a blessing in disguise: he missed the first time. He had to reload the gun," he said, adding that "a situation like this never crossed my mind. I know the guy only very superficially."

Police meanwhile said it was too early to say what the motives might have been for the attack, and would only identify the shooter as a man born in 1989 and living in Orivesi who had not been a pupil at the school.

"The shooter had licences for three hunting guns and he used two of them during the shootings," chief inspector Jari Kinnunen from the nearby town of Tampere told a news conference, adding the man had surrendered at the school "without police having to use force."

"The incident is over and no-one has been wounded," he said of the school attack.

Finland has had two school massacres in recent years.

In November 2007, 18-year-old Pekka Eric Auvinen shot dead eight people in a high school in Jokela, north of Helsinki, before turning the gun on himself.

Less than a year later, in September 2008, 22-year-old culinary arts student Matti Saari killed 10 people in a classroom in the small town of Kauhajoki before committing suicide.