A flag of the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) was found in the room of an Afghan refugee who was shot dead by German police after attacking train passengers with an axe and knife, officials say.

The 17-year-old injured at least four people, two critically, and was shot dead as he fled on Monday night near the southern city of Wuerzburg. Four of the injured were from Hong Kong.

The ISIL-linked Amaq news agency said on Tuesday the teenager was a "fighter" for the group and had "carried out the operation in answer to the calls to target the countries of the coalition fighting the Islamic State".

Amaq later released what it claims is a video of the train assailant, heard saying he is one of the group's fighters and that he intends to carry out a suicide attack in Germany.

Bavarian state Interior Minister Joachim Herrmann told Reuters TV that a hand-painted ISIL flag was found among the teenager's belongings when police searched his home.

However, Herrmann said it was still too early to say whether the youth was a member of the group.

Al Jazeera's Dominic Kane, reporting from Berlin, said the teenager "came to Germany as an unaccompanied refugee" and had "been in the care of a welfare organisation", citing the interior ministry in Bavaria.

Authorities "are looking into what may have been said [by the assailant] during the incident", Kane said.

The attack happened around 19:15 GMT on the train, which runs between Treuchlingen and Wuerzburg in Bavaria.

The incident is likely to deepen worries about so-called "lone wolf" attacks in Europe, and could put political pressure on German Chancellor Angela Merkel.

Bavaria is governed by the Christian Social Union (CSU), sister party to Merkel's conservative Christian Democrats.

Merkel's popularity has rebounded recently but the attack in Bavaria is likely to revive political tensions.

Germany welcomed about one million refugees in 2015, including thousands of unaccompanied minors. Many were fleeing war in countries such as Syria, Iraq and Afghanistan.

In May, a mentally unstable 27-year-old man carried out a similar knife attack on a train in southern Germany, killing one person and injuring three others. He is being held in a psychiatric hospital.