A Syrian suicide bomber who injured more than a dozen people when he blew himself up in Germany pledged allegiance to so-called Islamic State 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.

He was refused asylum a year ago.

He detonated his device after being turned away from a music festival.

The self-styled IS said it was behind 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 yesterday evening, was a "terrorist attack".

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

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

Storage devices containing "Salafist [ultra-conservative movement] content" were also seized at the property.

It is thought the attacker was carrying the bomb in a rucksack that 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 120km 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 2 July and was known to the authorities after committing two offences.

He had received two deportation notices and was told on 13 July 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.

A government spokesperson said it was too early to decide on changes to Germany's refugee policy before the results of the investigation into the attack were published.

"The acts of the last days and weeks do not show a uniform picture," said Ulrike Demmer. "Most terrorists who carried out attacks in Europe over the last months were not refugees."

German newspaper Die Welt quoted Bavarian Interior Minister Joachim Herrmann earlier as saying: "My personal view is that it is unfortunately very likely that a real Islamist suicide attack took place here."

Last night’s incident, on top of three other attacks since 18 July that left ten people dead and 34 injured, will fuel growing public unease about Chancellor Angela Merkel's open-door refugee policy.

More than a million migrants have entered Germany over the past year, many fleeing war in Afghanistan, Syria and Iraq.

Police said three of the 12 wounded were in a serious condition after the attack in Ansbach, a town of 40,000 people southwest of Nuremberg that has a US Army base.

The man had been in treatment after twice before trying to kill himself, though yesterday’s explosion was more than just "a pure suicide attempt", Mr Herrmann told Reuters.

An Islamist link could not be ruled out, he told reporters earlier.

Police offficers stand guard as they lock down an area following the explosion in Ansbach

Police officer in protective gear

Mr Herrmann said the recent attacks raised serious questions about Germany's asylum law and security nationwide.

He planned to introduce measures at a meeting of Bavaria's conservative government tomorrow to strengthen police forces, in part by ensuring they have adequate equipment.

One US intelligence official, speaking on condition of anonymity, said investigators would focus on what the bomber was doing before he left Syria and why he was denied asylum.

US security sources said the bombing did not appear to be a well-planned operation.

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 last Monday.

Earlier yesterday, a 21-year-old Syrian refugee was arrested after killing a pregnant woman and wounding two people with a machete in the southwestern city of Reutlingen, near Stuttgart.

A week ago a 17-year-old youth who had sought asylum in Germany was shot dead by police after wounding five people with an axe near Wuerzburg, also in Bavaria.

He was initially thought to be Afghan but federal Interior Minister Thomas de Maiziere has since said he may have been from Pakistan.

Police said neither yesterday’s machete attack nor Friday's shooting in Munich bore any sign of connections with the so-called Islamic State or other militant groups.

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.

IS claimed responsibility for the Wuerzburg attack as well as the 14 July attack in the French Riviera city of Nice in which a Tunisian man drove a truck into Bastille Day crowds, killing 84 people.