A man armed with a long knife killed three people and injured five others, some seriously, in Germany's southern city of Wuerzburg on Friday before being shot by police and arrested, authorities said.
Police identified the suspect as a 24-year-old Somali man living in Wuerzburg. His life was not in danger from his gunshot wound, they said.
Bavaria's top security official Joachim Herrmann said the injured include a young boy, whose father was probably among the dead.
The suspect was in psychiatric treatment before the attack and had been known to police, Herrmann said. There was no immediate word on a possible motive.
Videos posted on social media showed pedestrians surrounding the attacker and trying to hold him at bay with chairs and sticks.
A woman who said she had witnessed the incident told German RTL television that the police then stepped in.
"He had a really big knife with him and was attacking people," Julia Runze said. "And then many people tried to throw chairs or umbrellas or cellphones at him and stop him."
"The police then approached him, and I think a shot was fired, you could hear that clearly."
Police spokeswoman Kerstin Kunick said officers were alerted around 5 p.m. (1500 GMT) to a knife attack on Barbarossa Square in the center of the city. Würzburg is a city of about 130,000 people located between Munich and Frankfurt.
Bavaria's governor Markus Soeder expressed shock at the news of the attack. "We grieve with the victims and their families," he wrote on Twitter.
"A big thank you and respect for the spirited intervention by many citizens, who confronted the suspected attacker in a determined way," Soeder added. "And also to all first responders for their work at the scene."
Almost five years ago, a 17-year-old refugee from Afghanistan wounded four people with an ax on a train near Wuerzburg. He then fled and attacked a woman passerby before police shot him dead.