NYPD cops tracked a shipment of bogus police IDs to a Queens apartment, but what they found inside was a lot more terrifying.

Lee Bergman had an arsenal that included an AK-47 assault rifle, a pistol version of an AR-15, shotguns and 17,000 rounds of ammo inside the Far Rockaway home he shares with his wife and 2-year-old son, cops said.

The NYPD’s Internal Affairs Bureau Police Impersonation Unit launched an investigation into Bergman, 43, after police got a tip that he ordered NYPD identification cards over the Internet.

After intercepting the package, police conducted a search at 7 a.m. Tuesday and found two safes and the ammunition in buckets all over the on Shorefront Parkway home, cops said.

Police took Bergman into custody at his job at a light-manufacturing factory in Queens and brought him to the 100th Precinct station house, where he gave cops the code to a small safe, which contained five registered guns. But refused to divulge the combination for a larger safe, sources said.

Members of the NYPD’s Emergency Service Unit were able to force the safe open, revealing most of his stockpile.

In total, police seized the AK-47, eight handguns, five shotguns, two hunting rifles and six flare guns, along with the AR-15 pistol version that was stolen from Pennsylvania, authorities said.

Cops also recovered a fake NYPD shield, brass knuckles and four forged police identification cards.

Bergman was charged with various felonies, including criminal impersonation of a police officer, possession of forged instruments, weapons and narcotics offenses and numerous misdemeanors.

Bergman, who has worked at the light factory for more than 20 years, once aspired to be a cop, his mother told The Post.

“He wasn’t planning anything,” she said. “He’s obsessive compulsive. He wanted to be a cop, you know. But he didn’t do anything or harm anybody.”

She added, “I had no idea and his wife had no idea.”

Bergman’s wife of three years, Ana Antigua, said she was “shocked.”

“I’ve never seen [the weapons] before,” said Antigua, 30. “I live with him and I don’t know anything . . . As far as I know he was a smart, intelligent guy.”

Bergman asked police for a lawyer and won’t say why he had the arsenal, sources said.