BERLIN — A man wielding a large knife fatally stabbed one person and wounded five others on Friday during an attack at a supermarket in Hamburg, Germany, the police said. The assailant was arrested as he tried to flee.

The police said the attacker was a 26-year-old who was born in the United Arab Emirates, but did not release his name. Investigators said they were still trying to determine his citizenship, but Hamburg’s mayor, Olaf Scholz, said it appeared that the attacker was someone who should have been forced to leave Germany. The young man was not deported, Mr. Scholz said, because he did not have the necessary identification and travel documents.

“What makes me angry is that it appears the attacker is someone who sought protection here in Germany and then turned his hate against us,” Mr. Scholz said.

The police declined to offer any information to suggest a motive for the attack, but said they had not ruled out the possibility that it had been an act of terrorism.

Germany has been the target of several attacks by Islamist extremists in the last year, and officials have expressed concern about people who have returned to the country after fighting for the Islamic State in Syria or Iraq. Officials with the country’s Federal Criminal Office believe that there could be as many as 274 such people, and they do not have enough evidence to detain all of them.

There are also fears that terrorists may have entered the country during the wave of mass immigration in 2015.

A woman identified as a cashier at the supermarket told the private 24-hour news channel n-tv that the man had shouted “Allahu akbar,” which means God is great in Arabic, after he attacked people inside the store.

The assailant wounded other people on the street after he ran out of the supermarket but was wrestled to the ground by passers-by, who held him until police officers arrived. The German news media showed images of the attacker in the back seat of a police car, his face covered by a cloth stained with blood, which the police said came from injuries he had sustained.

The police identified the man who died only as a 50-year-old German, who was stabbed inside the supermarket. A 50-year-old woman and four men were wounded in the attack. The police said another man was hurt while helping to overpower the assailant.

Last summer, a string of assaults, including one by an unaccompanied minor refugee who attacked passengers on a train with an ax, and another refugee who detonated a backpack of explosives near a bar in southern Germany, rattled the country. Both attackers had pledged allegiance to the Islamic State, as did Anis Amri, the man who drove a truck into a Christmas market on Dec. 19, killing 12 people in the country’s worst terrorist attack in decades.