An NYPD cop who lost his $52,365 “disability” pension when he was caught doing construction work got it back — thanks to an unbelievable bureaucratic screw-up.

James Seiferheld, who lives in the tony Westchester town of Armonk, had 12 years on the force when he retired seven years ago with a three-quarters-pay, tax-free pension for “line of duty” injuries he claimed he suffered falling on ice and snow.

His alleged scam was exposed after cops got a tip about his new career and began an investigation. But in a shocking twist, the NYPD refused to take him back for new “medical” reasons — he was suspected of using cocaine.

The state’s highest court, the Court of Appeals, yesterday said it “reluctantly” had to rule that the 47-year-old former Harbor Unit officer is entitled to the money, despite its finding that “the case as a whole is very troubling.”

The court’s vote was 6-1.

Seiferheld can thank both the trustees of the police pension fund — and city officials who thought they could strip him of his pension without the trustees’ approval.

The trustees first approved Seiferheld’s pension in May 2004, accepting his claim that “he suffered from constant pain in his right shoulder and neck, loss of range of motion in his neck and shoulder and pain radiating into his arm, which prevented him from performing police duty,” according to court papers.

A month later, however, an NYPD official saw Seiferheld “performing construction work on a daily basis” and ratted him out.

An investigation was conducted and in December 2004 the trustees agreed to re-examine Seiferheld’s pension claim.

They referred the case to the NYPD’s Medical Board, which concluded in May 2005 that his condition “has improved dramatically.”

The trustees referred the case to the Medical Board twice more.

In September 2006, the Medical Board noted that Seiferheld “seems to have made a remarkable recovery from his injury.”

Acting on this, the pension trustees voted in April 2007 to return him to active duty.

But on July 6, 2007, he was “medically disqualified” when he was found to have cocaine residue in his hair.

That led the city’s Law Department to strip him of his pension on July 12, 2007.

Seiferheld, married with two kids, lost in a lower court, then went to the state Appellate Division, where he won, sparking an appeal by the city to the state’s highest court.

The judges rejected the city’s appeal, saying the Law Department did not have the authority to unilaterally take his pension.

The ruling said only the trustees could do that.

Not only will he get his yearly pension, he’s also seeking the benefits he was denied for the past four years.

“It is clear that given that the termination of his pension was unlawful and improper, he is entitled to the back monies,” said his lawyer, Robert Ungaro.