The U.S. House of Representatives passed a bill Wednesday that...

The city should settle with a scandal-scarred ex-NYPD commander ensnared in a hooker-fueled guns-for-favors case that included prominent Mayor Bill de Blasio donors — so both sides can avoid further embarrassment, a judge suggested Thursday.

“This is a case in which settlement discussions make sense,” Judge Andrew Carter told city lawyers and attorneys for James Grant, who claims in his lawsuit he was wrongly forced to retire before being cleared of charges at trial.

“There may be some value to quieting that chatter,” the judge said, noting the circumstances looked bad for the NYPD.

Grant was not in court Thursday, but lawyers for both sides agreed to try to hammer out a deal.

The ex-cop was acquitted in January, following a salacious trial, in which a hooker claimed she accompanied the officer and others on a private jet to Las Vegas and had sex with the married father of two.

Prosecutors claim Grant was plied with bribes by political donors in exchange for favors, including NYPD vehicular escorts and expedited pistol permits.