Emergency services are seen near a scene of a suicide attack in the southern German city of Ansbach late on 24 June, 2016 A Syrian migrant set off an explosion at a bar in southern Germany that killed himself and wounded a dozen others late Sunday, authorities said, the third attack to hit Bavaria in a week. The 27-year-old, who had spent a stint in a psychiatric facility, had intended to target a music festival in the city of Ansbach but was turned away because he did not have a ticket. / AFP PHOTO / dpa AND DPA / Daniel Karmann / Germany OUTDANIEL KARMANN/AFP/Getty Images

Special police officers examines the scene after an explosion occurred in Ansbach, Germany, Monday, July 25, 2016. Bavaria's top security official says a man who blew himself up after being turned away from an open-air music festival in the southern German city was a 27-year-old Syrian who had been denied asylum. (Friebe/dpa via AP)

A special police officer examines a backpack at the entrance of a building in Ansbach, Germany, Monday, July 25, 2016. Bavaria's top security official says a man who blew himself up after being turned away from an open-air music festival in the southern German city was a 27-year-old Syrian who had been denied asylum. (AP Photo/Matthias Schrader)

A backpack lies at the entrance of a building in Ansbach, Germany, Monday, July 25, 2016. Bavaria's top security official says a man who blew himself up after being turned away from an open-air music festival in the southern German city was a 27-year-old Syrian who had been denied asylum. (Daniel Karmann/dpa via AP)

A special police officer examines the scene after an explosion occurred in Ansbach, Germany, Monday, July 25, 2016. Bavaria's top security official says a man who blew himself up after being turned away from an open-air music festival in the southern German city was a 27-year-old Syrian who had been denied asylum. (AP Photo/Matthias Schrader)

Police officers secure the area after a bomb attack in Ansbach, Germany, Monday, July 25, 2016. Bavaria's top security official says a man who blew himself up after being turned away from an open-air music festival in the southern German city was a 27-year-old Syrian who had been denied asylum. (AP Photo/Matthias Schrader)

A special police officer secures a street near the house where a Syrian man lived before the explosion in Ansbach, southern Germany, Monday, July 25, 2016. The man who blew himself up and injured a dozen of people after being turned away from an open-air music festival was a 27-year-old Syrian who had been denied asylum, Bavaria's top security official said early Monday. (AP Photo/Matthias Schrader)

Special police officers secure a street near the house where a Syrian man lived before the explosion in Ansbach, southern Germany, Monday, July 25, 2016. The man who blew himself up and injured a dozen of people after being turned away from an open-air music festival was a 27-year-old Syrian who had been denied asylum, Bavaria's top security official said early Monday. (AP Photo/Matthias Schrader)

Police employees wait outside a house where a 27-year-old Syrian lived before an explosion in Ansbach, Germany, Monday, July 25, 2016. Bavaria's top security official says a man who blew himself up after being turned away from an open-air music festival in the southern German city was a 27-year-old Syrian who had been denied asylum. (AP Photo/Matthias Schrader)

Special police officers secure a street near the house where a Syrian man lived before the explosion in Ansbach, southern Germany, Monday, July 25, 2016. The man who blew himself up and injured a dozen of people after being turned away from an open-air music festival was a 27-year-old Syrian who had been denied asylum, Bavaria's top security official said early Monday. (AP Photo/Matthias Schrader)

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.