In bizarre twist the NYPD detective that handled the lineup of a pervy Google executive accused of rape was recently demoted for allegedly trying to seduce an unrelated sex crimes victim and the defense wants to question him about it, it was revealed Wednesday at a hearing.

Justin Chan, 28, is charged with raping a 19-year-old woman he’d just met and brought back to his apartment on E. 12th St in June of 2014.

NYPD Officer Lukasz Skorzewski testified Wednesday at the hearing in Manhattan Supreme Court that he showed a photo array to the victim then organized a lineup of the defendant.

Then the subject shifted from Chan’s alleged crime to the crooked cop’s sordid past.

Skorzewski’s attorney Michael Martinez approached the bench and urged Justice Charles Solomon not to turn over to the defense records relating to the investigation of his client.

Skorzewski is charged with groping a rape victim in Seattle after interviewing her about her case. She reported the married cop to the NYPD’s Internal Affairs Bureau, which substantiated her claims, law-enforcement sources said.

“Obviously, he was demoted in rank,” said Solomon. “He was stripped of his firearm and assigned to the Medical Unit. Aren’t those forms indicating what the police department found in their investigations, aren’t those things that the defense should have?

The disgraced cop’s attorney argued against it. “It’s a pending disciplinary matter,” he said. “We will get there soon enough. He has been interviewed and charged. I think they’re in the process of coming up with an offer.”

“Isn’t what he is alleged to have done out in Seattle can’t that be considered on his, if it’s true, on his credibility as a witness at trial?” the judge asked.

Martinez argued it shouldn’t because it happened a year prior to the current case and has nothing to do with it.

He also expressed concern that if the defense cross-examined Skorzewski about the allegations, he’d have to advise his client to invoke his right to silence and it could hurt the case against Chan.

But prosecutors indicated they had no intention of calling the sleazy cop as a witness at trial.

Additional reporting by Matt McNulty