An NYPD cop was grazed by a bullet when his gun accidentally fired in a Brooklyn housing project Friday night, police said.

The bullet grazed the on-duty officer’s groin area in the Wyckoff Gardens Houses at about 8 p.m., a police source said.

He was taken to an area hospital and is expected to make a full recovery, authorities said.

Police are investigating the incident. It was not immediately clear how the officer’s gun went off.