One person was killed and six others were injured when a failed asylum-seeker brandishing a knife attacked shoppers in a Hamburg supermarket, shouting "Allahu Akbar" before being overpowered by passers-by.

The attack had been motivated by "hate," mayor Olaf Scholz said, although he stopped short of declaring it a terrorist incident. "It makes me especially angry that the perpetrator appears to be a person who claimed protection in Germany and then turned his hate against us," he said.

If confirmed as an Islamist attack, it would be the first in Germany since Tunisian Anis Amri drove a truck into crowds at a Berlin Christmas market on December 19, killing 12 and injuring 48.

Police said that the man was a 26-year-old born in the United Arab Emirates, but were unable to immediately confirm his nationality or identify the motive behind the violence. He was identified as Ahmad A., who had arrived in Germany seeking asylum and had contact with the Islamist scene as well as a history of mental health problems and drug use. Germany has been on high alert about the threat of a jihadist attack since Amri's rampage in Berlin, for which the Islamic State group claimed responsibility. Jihadists have also carried out a string of random assaults in European countries using knives. Like the Hamburg attacker, Amri was a failed asylum seeker who could not be deported for lack of documents.

The attacker had been scheduled to be deported, but the process had been held up as he lacked identity papers, Scholz said.