Joachim Herrmann, the interior minister of Bavaria state, said officials were still investigating the motive for the attack.
He was responding to reports some witnesses had heard the suspect shout “Allahu Akbar” (God Is Great) during the assault.
A handmade Islamic State flag was found among the belongings of the teenager, Mr Herrmann said.
Hand-painted ISIS flag found in room of Bavaria train attacker
Police discovered a hand-painted Islamic State (IS, formerly ISIS/ISIL) flag in the room of the Afghan teen who attacked passengers on a train in Germany before being shot by police, the interior minister for the state of Bavaria said on Tuesday.
Police have also found documents proving the Afghan teen who attacked passengers on the train in Wurzburg had links with Islamic State (IS, formerly ISIS), German N24 channel reported, citing a source close to the investigation, as cited by RIA Novosti. Meanwhile, the terror group has said the attacker was one of its fighters, according to IS-affiliated Amaq news agency.