Three people were killed and others injured on Friday in a knife attack in the southern German city of Wuerzburg.
Police arrested the man, identified as a 24-year-old Somali resident of the city, after shooting him in the leg.
German news outlets reported that the suspect had attacked people in the city centre with a knife at around 5pm.
Video footage circulating online showed passersby 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.
The police said in a statement that “The attacker was overpowered after the police used firearms” and that there was no further danger to the public.
They did not provide details on the suspect’s motives. However, the man was in psychiatric treatment before the attack and had been known to police, Bavaria’s top security official Joachim Herrmann said.
A huge police deployment was ongoing in the city of some 130,000 inhabitants located about 120 kilometres (75 miles) west of Frankfurt.
While the motive has not yet been established, Germany has been on high alert after several attacks by Islamist extremists in recent years. The deadliest was a truck rampage at a Berlin Christmas market in December 2016 that killed 12 people.
Since 2009, German authorities have foiled 17 suspected jihadist attacks – the majority in 2016, according to the interior ministry.
But there have been other attacks, too.
In October 2017, a knife-wielding man randomly attacked passersby in central Munich, lightly injuring eight people. Police excluded terrorism as a motive after detaining the suspected perpetrator.