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.
Investigators found records showing that the man had been treated at a psychiatric institution, and police said he was not a known Islamist.
Chancellor Angela Merkel said the investigations will show what drove the man to go on his rampage.
“But what is certain is that the horrific act is directed at all humanity and every religion,” her spokesman Steffen Seibert tweeted.
But the far-right AfD party immediately seized on the violence that has erupted just three months before the general elections.
(article continues below)
See also on The Local:
The anti-immigration party’s co-leader Joerg Meuthen noted 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 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.
Spiegel Online reported the suspect had said in an interrogation that the act was his “jihad”.
If confirmed as an Islamist act, the case risks reopening a bitter debate in Germany over immigration – a topic that has taken a backseat so far in this year’s election campaign, compared to the last polls in 2017 when the AfD won seats in parliament for the first time.
‘Sad and shocked’
In the Bavarian city, residents brought flowers and candles in the morning to the scene of the stabbing.
“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 brought candles with a friend.
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. “We are mourning in all of Germany today with the relatives of the victims,” he said, also wishing the injured a swift recovery.
Two of the five seriously hurt were still in a critical condition, said Bavaria’s interior minister Joachim Herrmann.
Local media reported that all three deaths occurred at the household goods
store, where the suspect had gone to get his knife.
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.
While the perpetrator’s motive remains unclear, Germany has been on high alert after several Islamist 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 before being shot dead by police. The attack was claimed by the Islamic State group.
In Germany’s deadliest Islamist attack, a Tunisian jihadist rammed a truck into a Berlin Christmas market in December 2016, killing 12 people.
More recently, one man was killed by a 20-year-old Syrian jihadist in a knife attack in Dresden in October.
The number of Islamists considered dangerous in Germany rose sharply between 2015 and 2018, according to security services.
Some 615 are 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.