The attack took place as the train was traveling between stations.
The train made an emergency stop short of the station at Wurzburg-Heidingsfeld and the assailant jumped out of the train, Hench said. Police shot dead the suspect, a 17-year-old as he attempted to flee the scene.
"It is quite probable that this was an Islamist attack," said a ministry spokesman, adding that the attacker had apparently shouted "Allahu akbar" (God is greatest) as he stabbed people.
The attacker was said to have been carrying "weapons for slashing and cutting”, according to German media reports, including an axe.