The Afghan refugee was one of the fighters of the Islamic State group, the IS-linked Amaq news agency reported even as investigators were probing if he was recently radicalised.
The teenager carried out the late Monday night attack "in response to calls for attacking the countries which are members of the US-led coalition fighting against the IS", Efe news cited the agency as saying in a statement.
Four of the victims were in critical condition, German officials said.
An eye witness said the train carriage "looked like a slaughterhouse".
The attacker, who arrived without his parents to Germany about two years ago and was staying with a family in Ochsenfurt, was shot dead by police as he fled.
German police said it were investigating whether the 17-year-old man was motivated by religious extremism as he shouted "Allahu Akbar" (God is great) during the assault and later a hand-painted IS flag was found in his room.
People in contact with the suspect in recent months said the attack was "totally incomprehensible", and that he was a believer but did not appear "radical" or "fanatical".
According to them, the suspect went to the mosque on certain days, but not every week.
This website uses cookies.