Investigators were racing Saturday to pinpoint the motive of a man who went on a knife rampage in the German city of Wuerzburg, killing three people and leaving five seriously injured.

The suspect, a 24-year-old Somali who arrived in Wuerzburg in 2015, staged the attack in the city centre on Friday evening, striking at a household goods store before advancing to a bank.

He was later overpowered by police after they shot him in the thigh, Bavaria’s interior minister Joachim Herrmann said.

Investigators found records showing that the man had been treated at a psychiatric institution, and police said he was not a known Islamist.

“The police investigation will determine if this was an Islamist act or if it was due to the psychiatric state” of the man, said Herrmann.

But the case was immediately seized on by the far-right AfD, with the party’s co-chair Joerg Meuthen noting that a witness had reportedly heard the suspect shouting “Allah Akbar” (God is greatest).

Meuthen lamented the latest “Islamist knife murders in the middle of Germany,” adding that it was a “tragedy for the victims, who have my sympathy and another manifestation of Merkel’s failed migration policy”.

The AfD has railed that Chancellor Angela Merkel‘s decision to allow in more than one million asylum-seekers — many fleeing Iraq and Syria — since 2015 has contributed to a heightened security risk.

Residents of the Bavarian city woke up in shock at the news, some bringing flowers and candles in the morning to the scene of the stabbing.

“It’s terrible. I’m extremely sad and shocked and that’s why I’m here. I find that’s the least one can do — show sympathy,” said Wuerzburg resident Franziska, who together with a friend, brought candles.

Others were asking police officers stationed at the site what had happened, an AFP reporter witnessed.

President Frank-Walter Steinmeier voiced shock at the “extreme brutality” of the crime.

“He will be held to account by the rule of law for this inhumane act,” the president said.

“We are mourning in all of Germany today with the relatives of the victims,” he said, also wishing the injured a swift recovery.

Video footage circulating online showed passers-by trying to stop the suspect using folded chairs.

A crowd of people gave chase before a police car arrived on the scene, one video showed.

Praise poured in from political leaders thanking the civilians for their courage.

“My great respect goes to the brave citizens who quickly intervened,” tweeted Armin Laschet, the leader of Merkel’s CDU party, sending his condolences to relatives of the victims.

While the perpetrator’s motive remains unclear, Germany has been on high alert after several Islamist extremist attacks.

Wuerzburg was itself hit five years ago by an axe-wielding man who seriously wounded four people on a train.

The suspect, an Afghan, sought to attack a passerby as he fled before being shot dead by police.

The attack was claimed by the Islamic State group.

The deadliest Islamist attack in Germany happened in December 2016, when a jihadist rammed a truck into a Berlin Christmas market killing 12 people.

The Tunisian attacker, a failed asylum-seeker, was an IS supporter.

More recently, one man was killed and another seriously injured in a knife attack in Dresden in October.

A 20-year-old Syrian jihadist in May received a life sentence for the homophobic attack.

The number of Islamists considered dangerous in Germany rose sharply between 2015 and 2018, according to security services.

But the numbers have declined since then, with 615 considered dangerous by the latest count compared with 730 in January 2018.

Germany remains a target for jihadist groups, in particular because of its involvement in the coalition fighting IS in Iraq and Syria, and its deployment in Afghanistan since 2001.