A note found in the Afghan train attacker's room where he also kept a hand-painted flag of the Islamic State (ISIS) group indicates he may have been self-radicalised, a top German top security official said Tuesday.

Bavarian Interior Minister Joachim Herrmann told reporters that the 17-year-old Afghan asylum seeker, who shouted "Allahu akbar" as he attacked people on a train Monday night in southern Germany, had written notes in Pashtun that indicated he may have self-radicalised.

ISIS claimed responsibility for the attack which was posted on the group's Aamaq news agency on Tuesday.

Herrmann said people close to the attacker told investigators he had seemed like a calm person, not overtly religious or an extremist.

The 17-year-old, whose name has not been released, attacked passengers with an ax and knife on a train near Wuerzburg-Heidingsfeld on Monday night, before he was shot and killed by a special police unit which happened to be nearby.

"Even during the first emergency call, a witness said that the attacker was shouting 'Allahu akbar' on the train," Herrmann told ZDF Television earlier. "Also, during the search of his room, a hand-painted IS flag was found."

Four people on the train were injured, along with a woman outside as the attacker fled.

Herrmann said that it was too early to draw conclusions about the attacker's motive.

The attacker came to Germany two years ago as an unaccompanied minor, and applied for asylum in March of last year.

He lived in a home for young refugees until two weeks ago when he was placed with a foster family in the Wuerzburg area. Investigators were talking to the foster family, witnesses and the attacker's friends.

The attacker injured at least four people on the train near Wuerzburg-Heidingsfeld on Monday night, and also a woman outside the train as he fled. Witnesses said the interior of the train was covered with blood and looked "like a slaughterhouse," the German news agency dpa reported.

About 30 passengers were on the train at the time; more than a dozen were treated for shock.

The attacker jumped off the train after someone pulled the emergency cord and got about 500 meters away before the police special unit chased him.

As police drew near, the assailant started attacking the officers and was shot, dpa reported, quoting Herrmann.

On Tuesday morning, officers could be seen removing the attacker's body from the scene. Hong Kong's top official, Chief Executive Leung Chun-Ying, condemned the attack and extended his sympathies to the victims and their families.

The mayor of Wuerzburg condemned the attack. "I'm shocked by this horrible act of violence," Christian Schuchardt said, adding that his thoughts were with the victims and other passengers "who have suffered severe injuries on their bodies and souls by this act of craziness."

German officials did not identify the victims, but Hong Kong's immigration department said Tuesday that among those injured in the attack were four members of a family of five from the southern Chinese city.

The university hospital in Wuerzburg confirmed that it was treating three patients with life-threatening injuries, including two from Hong Kong.

Hong Kong's top official, Chief Executive Leung Chun-Ying, condemned the attack and extended his sympathies to the victims and their families.

Dpa reported that the attacker injured the 62-year-old father, the 58-year-old mother, their adult daughter and her boyfriend. The teenage son was not injured.

The father and the boyfriend had tried to defend the other family members, dpa said.

Germany last year registered more than 1 million asylum seekers entering the country, including more than 150,000 Afghans.

In May, a man stabbed four people at a German train station in a random early-morning attack in Grafing near Munich. One man later died.

The attacker, a German citizen, also shouted "Allahu akbar" during the attack, but authorities found no evidence of links to Islamic extremists. He was later sent to a psychiatric hospital.

Have something to add to this story? Share it in the comments.