A pack of crooks stole an ex-NYPD cop’s gun when he tried to stop a robbery on the Lower East Side, authorities said Sunday.

The 49-year-old former police officer was visiting a friend who works at the Chinese Hispanic Grocery store at Eldridge and Broome streets at around 5:10 a.m. Saturday, when he saw a robbery taking place outside, according to officials.

His training kicked in and he intervened, but the three robbers started whaling on him, officials said.

Amid the fracas, his holstered 9mm Glock fell to the ground, knocking its magazine out, according to officials.

The robbers snatched the fallen handgun and fled, but the quick-thinking officer was able to grab the bullets before the bad guys could, authorities said.

The ex-cop was taken to Woodhull Hospital, where he was treated and released.