Three victims were seriously injured, while fourteen other passengers were being treated for shock.
The attacker was shot dead while trying to flee.
The attack happened on a train near the city of Würzburg. The rail line connecting Würzburg-Heidingsfeld and Ochsenfurt has since been closed.
A police spokesman had previously said that approximately 10-15 people were wounded. A police operation was still ongoing.
Some of the victims' injuries are life-threatening, according to German news agency DPA.
Hubschrauber kreisen über #Würzburg Heidingsfeld. Keiner gibt derzeit Infos raus. Situation undurchsichtig. pic.twitter.com/C34BH1iqDj Polizei will sich jeden Moment bei meinem Kollegen melden. Noch ist kein Amoklauf bestätigt. #würzburg pic.twitter.com/CLZtTgPpXB
This story is developing. New information will be added as details emerge.