Authorities in Germany were investigating on Saturday what prompted a man to go on the rampage with a knife in the town of Wuerzberg on Friday, killing three women and seriously injuring five other women.
Officials said the suspect, whose rampage was halted when police arrested him, was a 24-year-old Somali immigrant who had had mental health problems in the past. As is the practice in Germany, they did not name him.
Officials assume the suspect was acting alone, but are still investigating whether there was any Islamist motive for the attack, regional Interior Minister Joachim Herrmann told a news conference.
Herrmann cited one witness as saying that before starting his spree the suspect had shouted "Allahu akbar", an Arabic phrase that means "God is great" and that is often associated with acts of Islamist militancy when used by attackers.
"The indications of radicalisation, in this case Islamism, and of psychological problems do not necessarily rule one another out ... this must be the subject of further investigation," Herrmann said.
The man went into the kitchen department of a store and asked an assistant where the knives were, regional police president Gerhard Kallert said. He seized a knife and stabbed and killed the saleswoman and two more women in the shop.
He then injured five other women seriously, as well as wounding a child, in a bank and on the street.
He was cornered by passers-by before the police shot him in the thigh, Kallert said.
Police found the man's phone and pamphlets with hateful messages during a search of the homeless shelter, but were still evaluating them, Kallert said, adding that it was not yet clear whether the suspect had purposefully targeted women.
One of the injured was still fighting for her life, while two had been released from hospital, police president Martin Wilhelm told the news conference.
Residents laid flowers and candles outside the store.
The suspect had lived in Wuerzburg since 2015, the year Germany opened its borders to more than a million migrants and refugees fleeing war and poverty.
He was registered as living at a facility for the homeless and had twice this year been put into compulsory psychiatric treatment, once after a fight with fellow residents involving a knife but no injuries, prosecutor Wolfgang Gruendler said.
Five years ago, Wuerzburg, an ancient city of 130,000 people some 100 km south-east of Frankfurt, was the scene of a knife attack on a train by a 17-year-old Pakistani asylum seeker in which five people were injured, two seriously.