A man threatened to shoot up a Harlem bodega Friday and was fatally stabbed by a store worker, according to police sources and witnesses.

The bodega worker, 22-year-old Ahmed Hafeed, was charged with second-degree murder for the slaying of a 46-year-old at A&S Candy Grocery Inc. on West 145th Street near Malcolm X Boulevard, police said late Friday night.

The two men had argued earlier, with the victim threatening to bring back a gun, law enforcement sources said.

When he did return at around 9 a.m., the victim wasn’t packing heat — but did bum-rush the counter and got into a tussle with Hafeed, who was stabbed in the skirmish, according to sources and witnesses.

Surveillance footage shows Hafeed pocketing a knife before stepping out from behind his plexiglass-protected counter as the attacker approaches.

It also shows a second guy coming in with the 46-year-old — but he fled mid-fight.

Cops say they don’t know if the slain man also had a knife — but one witness says she saw him brandishing one first.

“I seen him walk in, they started arguing and going at it, then [Hafeed] start telling me, ‘Go, go, go’ when [the attacker] pulled out the knife,” said Laverne Allen, 57.

After he was stabbed, the bloodied man stumbled up the street to a Dunkin’ Donuts, and was later pronounced dead at Harlem Hospital