A retired government employee from New Jersey gunned down a security guard inside a Soho federal building on Friday — and then used the same weapon to kill himself, police said.

Kevin Downing, 68, of Fort Lee, strode into the Varick Street building with a bag in his hand at 5:05 p.m. and approached armed security guard ­Idrissa Camara, 53, who was manning the lobby’s metal detectors.

When Camara told him he had to check his belongings, Downing dropped the bag and shot the guard once in the head with a .38-caliber Smith & Wesson handgun, law-enforcement sources said.

“He had no opportunity to defend himself,” said a source who watched the ­security video.

Downing then calmly walked through the security area toward an elevator bank, where he came upon another employee — at which point Downing turned around and shot himself in the head, police officials said. Downing was pronounced dead at the scene.

Camara, who lived in Harlem, was taken to a nearby Lenox Hill Hospital annex, where he died.

The Ivory Coast native and father of four was scheduled to finish work at 4 p.m. but agreed to stay late for extra duty, said a company spokesman for the private contractor that employed him.

Downing had ranted in an online petition about being fired from the Bureau of ­Labor Statistics because he blew the whistle about “inexcusable taxpayer waste.”

The building where he shot Camara houses offices of the bureau, among other agencies including a federal immigration court, raising the possibility he was targeting the agency or boss who had fired him.

“We don’t know if he worked at this building or another location because he left the government some time ago,” said John Miller, the top NYPD counter-terrorism official.

Camara’s relatives wept outside his Harlem apartment, including his two sisters who were visiting from Africa. One wailed, “My brother, my brother.’’

The slain security guard had four children, including an adult daughter serving in the US Army and a ­2-year-old daughter.

“This loss is very big for us,” said Camara cousin Ouattara Muhamed.

“He’s taking care of his own family here and back home in Africa.”

Camara’s heartbroken wife visited the hospital where he died Friday evening and was crying softly when she returned to their Harlem home at about 10:30 p.m.

A neighbor who lives across the street from Downing in Fort Lee and has known him for many years said he was “a nice old man” who worked in real estate, sometimes walked with a cane and has lived alone since his wife died a few years ago.

“He always smiled. He was always in a good mood. Maybe he had a double personality or something,” said the woman, asked not to be identified.

“Nobody come over, no friends. He was always alone,” she said.

Another neighbor, John Demato, said, “I’m shocked because that man was very quiet. He never did anything that drew attention to himself.”

Additional reporting by Gabrielle Fonrouge, Meghan McGibney and Melkorka Licea