Three people were seriously injured on Monday night after a 17-year-old Afghan refugee went on a stabbing rampage with a knife and an axe near the southern German city of Würzburg, some 280 kilometers (174 miles) north-west of Munich. The suspect was shot dead by police shortly after.

The incident occurred on Monday at around 9:15 p.m. local time (1915 UTC) on a regional commuter train traveling between the German towns of Treuchtlingen and Würzburg. Fourteen passengers were also treated for shock, while one other person sustained light injuries.

Watch video 00:40 Axe attack on German train

"Islamic State" (IS) flag found

Speaking on German television Tuesday, Bavarian Interior Minister Joachim Herrmann said investigators were making contact with people involved with the 17-year-old. He had been living in Würzburg since March, in a home for minors who had travelled to Germany unaccompanied to seek asylum. The foster family home where he had lived for the past two weeks was searched.

"A hand-painted IS flag was found in his room," Herrmann said.

"Islamic State" (IS) posted a video on Tuesday featuring an individual that the militant group identified as the perpetrator of the attack. In the clip the teenager is seen with a knife, saying he will use it to kill infidels.

Aamaq, a news agency linked to IS, said the group claimed responsibility for the attack and that the 17-year-old was its "fighter." The claim was phrased in a similar way to the IS response to the Bastille Day truck attack which killed 84 people in Nice, France last week.

Herrmann had earlier said investigators were following every lead to determine the teenager's motive and it was too early to say whether he had an Islamist background. So far, it was understood that he had acted alone.

Herrmann confirmed in an earlier television interview that the teenager boarded the train in Ochsenfurt, where he had been staying with a foster family.

"He suddenly attacked passengers with a knife and an axe, critically injuring several. Some of them may now be fighting for their lives."

The Afghan national reportedly shouted "Allahu Akbar," Arabic for "God is great," before launching the attack, wielding a knife and axe.

"The perpetrator was able to leave the train, police left in pursuit and as part of this pursuit, they shot the attacker and killed him," a police spokesman said. On Tuesday, Herrmann added that a police special unit happened to be in the area and was able to respond to the incident quickly.

Victims from Hong Kong

On Tuesday, Herrmann also told ZDF public television that two victims were in a critical condition. The four injured victims were a family from Hong Kong. Hong Kong's top official, Chief Executive Leung Chun-Ying, issued a statement condemning the attack and said representatives from the Hong Kong office in Berlin were visiting the victims in hospital. The "South China Morning Post" newspaper reported that the family included a father, mother, daughter and the daughter's boyfriend. Another family member, a son aged 17, was not hurt, the newspaper reported.

'We cannot guarantee 100 percent safety'

In light of the recent mass-casualty terror attacks in neighboring France and Belgium, German society is on heightened alert. Herrmann on Tuesday said police needed to be strengthened but it was clear that authorities could never guarantee 100 percent safety for citizens.

"There cannot be a police officer in every train," he said, adding that even though a lone attacker with a knife or axe could theoretically strike anywhere in Germany, the challenge for authorities was to do everything where possible to track people with bad intentions before they got out of control.