The assailant, armed with a knife and an ax, was identified as a 17-year-old Afghan man living in Ochsenfurt, Bavaria, Bavarian Interior Minister Joachim Herrmann said.
After the initial incident, the train's emergency brakes were deployed and the attacker fled into a nearby town, Herrmann said at a news conference Tuesday.
Police chased the attacker and then met him very close to the river where they confronted him, Herrmann said.
The teen was aggressive and tried to attack cops with his ax before they opened fire and killed him.
Herrmann said that a hand-drawn flag resembling the one used by ISIS was found in the attacker's room, and said that he shouted "Allahu Akbar" during the attack, according to initial distress calls.
He acted by himself, Herrmann said.
Though a pro-ISIS media group said the attacker was a "ISIS fighter," authorities cast doubt on that claim and it's believed to be unlikely that he was working under the direct supervision of the terror group.
The 17-year-old was taken in two weeks ago by a foster family, Herrmann said.
"This is a big mosaic puzzle right now and we will do everything to pull information together in order to assess his motivation," he said.
The teen came to Germany without his parents, according to Alexander Gross, a police officer in Bavaria.
The attack took place as the train was traveling between Treuchtlingen and Wurzburg. The train made an emergency stop short of the station at Wurzburg-Heidingsfeld and the assailant jumped out of the train, Hench said.
His motive is not yet known, Hench said.
Germany absorbed more than one million refugees last year. Some have been concerned over the presence of terror groups in the country -- both the potential for attackers to slip in with migrants and the concern that they may be able to radicalize disaffected youths.
Three Syrian men were arrested last month
on suspicions that they were planning to carry out a mass casualty attack in Dusseldorf.
Many 'in shock'
Four passengers who were attacked are in serious condition, with the total number of wounded unclear, according to the police spokesman.
Some 14 to 25 people were classified as "in shock" and treated at the scene, according to Gross.
At least four of those injured on the train were from Hong Kong, Hong Kong's chief executive, CY Leung, said in a statement.
Herrmann said that those four are the most seriously injured. They were from a family of five relatives traveling together.
One is currently battling life-threatening injuries, he said.
Approximately 20 to 30 people were on the train, according to Gross.
A Deutsche Bahn spokesperson confirmed that train service between the two stations has resumed.