The incident occurred on Monday night on a regional commuter train near the southern German city of Wurzburg, some 280 kilometers north-west of Munich.
German officials confirmed in a TV interview that the teenager had been staying with a foster family after traveling unaccompanied to Germany to seek asylum.
“The attacker appears to have been a 17-year-old Afghan who has been living in Ochsenfurt for some time,” Bavarian Interior Minister Joachim Hermann said. “He suddenly attacked passengers with a knife and an axe, critically injuring several. Some of them may now be fighting for their lives.”
Reportedly he has shouted “Allahu Akbar” before launching the attack, wielding a knife and axe.
The motive of the attack was not immediately clear.
Germany welcomed roughly 1 million migrants in 2015, including thousands of unaccompanied minors. Many were fleeing war in countries like Syria, Iraq and Afghanistan.