The 27-year-old Syrian suicide bomber who killed himself and injured 12 others in an attack in the Bavarian town of Ansbach pledged allegiance to the Islamic State, security officials have said, before he detonated a rucksack bomb.

Bavaria's security chief confirmed German police had discovered a video on the bomber's phone pledging allegiance to the leader of IS (Isis/Daesh) Abu Bakr al-Baghdadi.

The attacker was living in an apartment in Ansbach at the time of the attack, and could not be returned to Syria because of the dangerous conditions there.

German police released the age and nationality of the attacker, but have so far withheld his name. The man was reported to have attempted to kill himself two times while in psychiatric care since he arrived in Germany two years ago.

As authorities said 12 people had been wounded in the attack in the small Bavarian town of Ansbach, whether the attack was planned for either personal or political reasons remains unclear.

Prior to the discovery of the mobile phone video Bavaria's interior minister told reporters it was unclear whether the attacker planned just to kill himself or whether he hoped to carry out an Islamic State-style attack. Joachim Herrmann said he may have planned to "take others with him into death".