The claim was posted on the group’s Aamaq news agency on Tuesday.
It came just hours after a 17-year-old Afghan asylum seeker attacked passengers with an axe and a knife on a train near Wuerzburg-Heidingsfeld on Monday night, before he was shot dead by a special police unit.
The statement said 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-IS coalition.
Earlier, Bavaria’s interior minister Joachim Herrmann said on public television that the teenager had shouted “Allahu akbar” (“God is great”) during the attack, and that investigators raiding his room had found a hand-painted IS flag.
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, and more than a dozen were treated for shock.
On Tuesday morning, officers could be seen removing the attacker’s body from the scene.
Mr Herrmann said at least two victims - members of a Chinese tourist family - are still in a critical condition.
German officials have not yet identified the victims, but Hong Kong’s immigration department said on Tuesday that among those injured in the attack were four members of a family of five from the Chinese territory. The department said it is working to provide assistance to the family but did give not give details of their injuries.
The South China Morning Post newspaper reported that the family members hurt included the 62-year-old father, 58-year-old mother, 27-year-old daughter and her 31-year-old boyfriend. A 17-year-old son was not hurt.
Hong Kong’s most senior official, chief executive Leung Chun-Ying, condemned the attack and extended his sympathies to the victims and their families.
Germany last year registered more than one million asylum seekers entering the country, including more than 150,000 Afghans.
In May, a man stabbed four people at a German railway 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. The attacker was later sent to a psychiatric hospital.