Multiple people were injured after a teenage Afghan refugee went on a slashing spree armed with an axe and knife on a train in southern Germany on Monday night before he was shot to death by police, officials said.

Wuerzburg police said on their Facebook page that three of the victims suffered serious injuries and one was slightly injured. Another 14 people were being treated for shock.

Bavaria's top security official, state Interior Minister Joachim Herrmann, told Germany's ARD television that the attacker had been identified as a 17-year-old Afghan refugee.

Herrmann said initial information was that the suspect came to Germany as an unaccompanied minor and had lived in the Wuerzburg area for some time, initially at a refugee facility in the town of Ochsenfurt and more recently with a foster family.

He said authorities were still investigating the motive of the attack and were looking into reports that the suspect had yelled out "an exclamation" during the rampage.

He was responding to reports that some witnesses had heard the suspect shout "Allahu Akbar" ("God Is Great") during the attack.

The train was on its way from the Bavarian town of Treuchtlingen to Wuerzburg, which is about 60 miles northwest of Nuremberg.

Germany last year registered more than 1 million refugees entering the country, including more than 150,000 Afghans, but it was not immediately clear whether the suspect was among them or someone who had been in the country for a longer time.

The rampage came amid heightened security in Europe, days after 84 people were killed when a man who pledged allegiance to ISIS rammed a truck into a crowd in Nice, France after the conclusion of a Bastille Day fireworks show.

The Associated Press contributed to this report.