The attorney for a man who shot himself inside of Zabar’s told a Manhattan Criminal Court judge that his client ditched the gun in a nearby park in order to prevent any children from finding it.

Louis Leston Anderson, 49, reportedly told police that he found the .9mm handgun by the Lincoln Tunnel while sorting through some trash. He later shot himself in the leg with the weapon just after 9:30 a.m. Tuesday, while ordering a bagel at the Upper West Side store. 

He then allegedly limped away and discarded the gun at Riverside Park, according to DNAinfo.com.

“He didn’t want a child to find the gun and hurt themselves,” his defense attorney, Andrew Friedman, reportedly told the court. “The gun had been put somewhere where no child, no person could inadvertently fire it and injure themselves.”

Prosecutors rejected that argument, reportedly noting that Anderson placed the gun in a Ziploc bag and stashed it next to a rock by the arch in Riverside Park. 

“He discarded [the gun] in the park, in Riverside Park, a place where there are children all the time,” Assistant District Attorney Jennifer Sigall said, according to the DNAinfo report.

Anderson, who has nine prior arrests, was reportedly ordered held on $7,000 bail on weapons and reckless endangerment charges.