Ansbach: A failed Syrian asylum seeker who blew himself up outside a German music festival had made a video pledging allegiance to the Islamic State group, in the second attack claimed by the jihadists in Germany in a week.

The 27-year-old assailant wounded 15 people, four of them seriously, near a cafe in the southern city of Ansbach last night when he set off a bomb in his rucksack, killing himself.

"A video made by the assailant was found on his mobile phone in which he threatened an attack," Bavarian state interior minister Joachim Herrmann told reporters.

"After that he announced in the name of Allah that he pledged allegiance to (IS chief) Abu Bakr al-Baghdadi, well- known Islamist leader, and announced an act of revenge against Germans because they were standing in the way of Islam."

IS later said via the jihadist-linked Amaq news agency that the attacker "was a soldier of the Islamic State" who had acted "in response to calls to target nations in the coalition fighting" the extremists.

Europe's economic powerhouse was already reeling after nine people were killed in a shopping centre shooting spree in Munich on Friday and five people were wounded in an axe attack on a train in Wuerzburg on July 18 that was claimed by IS.

All three brutal incidents were in Bavaria, the southern state that is a gateway for tens of thousands of refugees under Chancellor Angela Merkel's liberal asylum policy.

Merkel's deputy spokeswoman Ulrike Demmer expressed the government's "shock" after the rash of attacks but also warned against branding all refugees a security threat.

"Most of the terrorists who carried out attacks in recent months in Europe were not refugees," she told reporters.

"The terrorism threat (among refugees) is not larger or smaller than in the population at large."

Police said the Syrian man intended to target the open-air festival but was turned away as he did not have a ticket, and detonated the device outside a nearby cafe.

"If he had made it inside, there would certainly have been more victims," a police spokesman said.

The explosion went off in the centre of the city of Ansbach, not far from where more than 2,500 people had gathered for the concert, at around 10 pm (2000 GMT).

The attacker, who came to Germany two years ago but had his asylum claim rejected after a year, had tried to kill himself twice in the past and had spent time in a psychiatric clinic, authorities said.

He was facing imminent deportation to Bulgaria, where he was first registered within the European Union as an asylum seeker and which had granted his claim, a German interior ministry spokesman said.

The assailant, who lived in Ansbach, was already known to police, having been linked to a drug-related offence. However a social worker who knew him, Reinhold Eschenbacher, described him as "friendly, inconspicuous and nice" when he came to his office pick up his welfare benefits, DPA news agency reported.