The man was reportedly carrying gasoline and gunpowder in his pockets as he entered the Mercadona shop, in As Lagoas, Ourense.
Numerous shoppers were inside making their purchases when the assailant, who was armed with a shotgun, entered and fired several shots.
Supermarket employees said he fired at least six shots during the terrifying ordeal.
One employee said the man, who was standing just a few metres from him, yelled "Allahu Akbar", which translates to "God is greatest".
Police arrived at the scene to arrest the attacker.
One witness told local media: "Agents came out with a vest shouting and pushing the people."