The detective hit the wrong target — himself.

A cop struck in the chest by the ricocheting fragment of a bullet that he had fired at the NYPD range in The Bronx is suing the city, charging that it failed to properly maintain and position the targets.

Jorge Morban, 46, was at the Rodman’s Neck range on July 26 when he fired and hit a stanchion several feet away.

Morban, a 14-year veteran who was not wearing a bulletproof vest, felt a sting on his chest and saw blood.

He was rushed to Jacobi Medical Center, and spent three weeks recovering, said his lawyer, Joseph Decolator.

“The [shooting] position was too close to the target stanchion — that’s why it reflected back at him,” Decolator said.

The lawsuit, filed last week, also claims the stanchion target “was broke, defective [or] misaligned.”

It seeks unspecified damages.

The City Law Department said it couldn’t comment because it hadn’t seen the lawsuit.