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 militants 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 on Sunday 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, the well-known Islamist leader, and announced an act of revenge against Germans because they were standing in the way of Islam."
IS goup later said via the militant-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.
IS group also claimed the axe rampage.
All three brutal incidents were in Bavaria, the southern state which has been 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
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.
Stephan Mayer, a deputy from Merkel's conservative bloc, said it was "completely wrong" to blame the government's refugee policy for the spate of assaults.
But Mayer told the BBC that the 1.1 million migrants and refugees Germany let in last year represented a "big challenge" for law enforcement, even as the influx has dwindled in recent months.
"We were not able to register and control all the migrants that crossed the German border," Mayer admitted.
Europe has been on edge for months after a string of deadly attacks claimed by IS, including bombings in Brussels and Paris and the carnage at Bastille Day celebrations in the southern French city of Nice.
Meanwhile police released more details on Munich mall attacker David Ali Sonboly, saying the 18-year-old was depressed and had spent two months in a psychiatric unit last year.
The teen, who had German and Iranian nationality, was obsessed with mass killings -- including Norwegian rightwing fanatic Anders Behring Breivik's 2011 massacre -- and spent a year preparing for the shooting spree, police said.
At least 35 people were also wounded during Sonboly's attack, which began at a McDonald's franchise and ended with him turning his 9mm Glock pistol on himself.
Investigators have ruled out any link with IS militants, although he appeared to have planned the assault with chilling precision for a year.
Police detained a 16-year-old Afghan friend in connection with the shooting but later released him for lack of evidence.
Already steeped in grief and shock, Germans were further rattled by news that a Syrian refugee had killed a 45-year-old Polish woman with a large kebab knife at a snack bar in the southwestern city of Reutlingen.
Police, who had initially said the murder weapon was a machete, added that Sunday's incident in which three others were injured was likely a "crime of passion".
Three people were also injured in the attack, which ended when the 21-year-old assailant was deliberately struck by a BMW driver trying to stop the man