Robert Dunbar, accused of shooting an off-duty New York City police officer in Manalapan, NJ. Photo:

The Staten Island man accused of shooting an NYPD detective he found in his estranged wife’s home has been indicted in Monmouth County, New Jersey.

A grand jury hit Robert Dunbar, 35, with attempted murder charges for allegedly grabbing the off-duty cop’s service weapon and firing of several shots, including one that hit the cop, Louis Pepe, in the back.

Dunbar’s lawyer said the shooter found the cop in bed with his estranged wife Aug. 12, 2012, after the couple’s child complained about strange men in the Manalapan, N.J. home.

Dunbar dropped by and found his wife, Deborah, naked in the bedroom with the off-duty cop and both men reached for the detective’s service weapon, a .38 revolver.

Dunbar’s lawyer has said the shooting was accidental and the estranged husband didn’t realize the man in the house with the gun and his wife was a cop.