Hamburg police said on Twitter that one suspect had been arrested but that it was too soon to pinpoint a motive.
Police confirmed the attacker was acting alone and said he was overpowered by members of the public.
There are unconfirmed reports that he shouted “Allahu akhbar”, Arabic for “God is great” while attacking people. Armed police are at the scene.
Bild newspaper published a photo of a man purported to be the attacker covered in blood and said he began wildly striking at shoppers before being stopped.
The attack happened in the Barmbek region in the north of the city in a branch of Edeka, Germany’s largest supermarket chain.
Police say the man’s weapon may have looked like a machete but they are, for now, assuming it was a kitchen knife.
He attacked customers in the supermarket at random, ran outside and was chased by customers and by people outside the shop. They brought him to the ground before he was detained by plain-clothes police officers.
Asked whether this was a terror attack a police official told the BBC: “We are at an early stage of the investigation… At the moment we can’t rule anything out. We are investigating all avenues.”
Speculation in German media said the attack may have been part of a robbery attempt but police said that that motive could not be confirmed.