Customers at a University City grocery stopped in their tracks Sunday when they heard gunfire among the food aisles.

It turns out, a man carrying a loaded gun in his waistband while in the Schnucks supermarket accidentally shot his own leg in the middle of the store.

Officers seized the gun at the store at 6920 Olive Boulevard about 5 p.m. The man was taken to a hospital with injuries that were not considered life-threatening, according to University City police.

The man told officers he was attempting to prevent the loaded firearm — which was not in a holster — from falling to the ground from his waistband, but in the process accidentally discharged a single round.

The bullet struck the floor, ricocheted and became lodged in the ceiling, according to University City police.

Police said a second person standing nearby was struck by unknown debris, but the bystander declined medical treatment.

The man with the gun was charged with one count of discharging a firearm, police said.

“I think you need to leave the gun in the car or not bring it at all here,” said Zachary Coleman, a University City Schnucks shopper Tuesday. “I don’t want to be shopping with a guy with a gun.”