At least four people have been injured at a station in Grafing, near Munich, by a knifeman shouting "Allah is great", German media have reported.
A police spokesman told the Bild newspaper that the attacker had been overpowered and arrested.
Broadcaster Bayrische Rundfunk reported that witnesses said the man shouted "Allahu Akbar".
One of the victims was said to have been seriously injured.