A Syrian suicide bomber who injured more than a dozen people when he blew himself up in Germany pledged allegiance to Islamic State (IS) and had a history of mental illness, it has emerged.

The attacker has been named locally as Mohammad Daleel, 27, a failed asylum seeker who was facing deportation to Bulgaria when he detonated his device after being turned away from a music festival.

The terror group claimed responsibility for the attack, saying the bloodshed was carried out by "one of the soldiers of the Islamic State".

The blast killed the suspect and injured 15 others, four of them seriously.

Bavarian interior minister Joachim Herrmann said a video had been found of Daleel announcing a "revenge" attack against Germany and pledging allegiance to the leader of IS.

He added that it suggested the bombing, which happened outside a wine bar in central Ansbach on Sunday evening, was a "terrorist attack".

Daleel repeatedly received psychiatric treatment, including for attempted suicide, and was known to authorities for minor drug offences.

The teenage gunman who slaughtered nine people in Munich on Friday had also been treated for a range of psychiatric problems in the lead-up to his attack, but had no known links to terrorism.

Germany has been reeling from four violent attacks in recent days, including three in Bavaria alone, following an IS-inspired axe rampage by a teenager on Monday.

Bomb-making materials were found alongside violent videos at the home of the Ansbach bomber, officials said.

Storage devices containing "Salafist content" were also seized at the property.

It is thought the attacker was carrying the bomb in a rucksack which contained sharp bits of metal, and Roman Fertinger, the deputy police chief in nearby Nuremberg, said it was likely there would have been more casualties if he had not been barred from the festival.

The nearby event was evacuated of more than 2,500 people following the explosion.

Bavaria police said security at three-day Ansbach Open music festival, around 90 miles north of Munich, noticed a young man acting suspiciously in the area at around 9.45pm.

He was turned away from the event for not having a ticket and at around 10.10pm he bent forward and the device was detonated.

Bystanders thought there had been a gas explosion at a nearby restaurant in the aftermath of the blast.

Witness Thomas Debinski described the "disturbing" scene in the small city as bystanders came to realise a violent act had taken place.

"People were definitely panicking, the rumour we were hearing immediately was that there had been a gas explosion," he told Sky News.

The concert was shut down and around 200 police officers and 350 rescue personnel flooded the scene, with investigators later confirming the blast had been caused by a bomb.

Mr Herrmann said the suspect was a Syrian whose application for asylum had been rejected, but he had been allowed to stay in Germany due to the civil war.

He had been living in Ansbach since July 2 and was known to the authorities after committing two offences.

He had received two deportation notices and was told on July 13 he would be deported to Bulgaria.

In January a programme was launched in the city to help refugees assimilate by teaching them the basics of law in their new host country.

The initiative came amid growing tensions and concerns in Germany over the large numbers of migrants, and taught lessons on freedom of opinion, the separation of religion and state and the equality of men and women.