The attack occurred shortly before 3 p.m. local time on a train bound for Hamburg and the assailant was subdued by passengers, officials said.