BERLIN — The Islamic State group has claimed responsibility for an attack on a train in Germany that injured at least five people.

The claim was posted on the group’s Aamaq news agency on Tuesday.

It came hours after a 17-year-old Afghan asylum seeker attacked passengers with an ax and knife on a train near Wuerzburg-Heidingsfeld on Monday night, before he was shot and killed by a special police unit which happened to be nearby.

The statement says the attacker was “a member of the Islamic State” group and carried out the attack in response to the militant group’s calls to attack countries that are members of the anti-Islamic State coalition.

“Even during the first emergency call, a witness said that the attacker was shouting ‘Allahu akbar’ on the train,” Joachim Herrmann, Bavaria’s interior minister, told ZDF Television. “Also, during the search of his room, a hand-painted IS flag was found.”

Herrmann said that it was too early to draw conclusions about the attacker’s motive.

The attacker, who was not identified by the authorities, came to Germany two years ago as an unaccompanied minor, and applied for asylum in March of last year. He lived in a home for young refugees until two weeks ago when he was placed with a foster family in the Wuerzburg area. Investigators were talking to the foster family, witnesses and the attacker’s friends.

The attacker injured at least four people on the train near Wuerzburg-Heidingsfeld on Monday night, and also a woman outside the train as he fled.

Witnesses said the interior of the train was covered with blood and looked “like a slaughterhouse,” the German news agency dpa reported. About 30 passengers were on the train at the time; more than a dozen were treated for shock.

The attacker jumped off the train after someone pulled the emergency cord and got about 500 yards away before the police special unit chased him. As police drew near, the assailant started attacking the officers and was shot, dpa reported, quoting Herrmann.

On Tuesday morning, officers could be seen removing the attacker’s body from the scene.

Herrmann said at least two victims — members of a Chinese tourist family — were in critical condition.

German officials did not identify the victims, but Hong Kong’s immigration department said Tuesday that among those injured in the attack were four members of a family of five from the southern Chinese city. The department said it is working to provide assistance to the family but gave no details of their injuries.

Dpa reported that the attacker injured the 62-year-old father, the 58-year-old mother, their adult daughter and her boyfriend. The teenage son was not injured. The father and the boyfriend had tried to defend the other family members, dpa said.

Germany last year registered more than 1 million asylum seekers entering the country, including more than 150,000 Afghans.

In May, a man stabbed four people at a German train station in a random early-morning attack in Grafing near Munich. One man later died. The attacker, a German citizen, also shouted “Allahu akbar” during the attack, but authorities found no evidence of links to Islamic extremists. He was later sent to a psychiatric hospital.