A respected long-time upstate judge agreed to resign after he was caught dishing out orders from the bench that helped him in a divorce case he was working privately as a lawyer.

New Paltz Justice Jonathan Katz was asked by authorities in late 2017 to sign an arrest warrant and order of protection — against the husband of a woman he was representing in their divorce.

But rather than declare a conflict of interest, the part-time justice signed the documents — and continued representing the man’s wife in the contentious split, according to authorities.

The protection order had been made without proving good cause and forced the husband out of the couple’s New Paltz home, a key thing Katz had been fighting for in the divorce, documents show.

A formal judicial conduct probe was launched in February, with Katz — a town justice for 24 years — resigning Thursday after copping to the complaints against him.

When he first voiced his plan to leave the almost $30,000-a-year job last month, he made no mention of the scandal.

“It’s time to let a younger person have the chance to experience the unmitigated joy of being a judge in such a wonderful town,” he told Hudson Valley One at the time. “My private law practice is growing, and I want to concentrate on that.”

But the New York State Commission on Judicial Conduct said Katz agreed to resign to end the formal disciplinary charges against him. He also agreed to never again seek judicial office.

“A judge must be and appear impartial if the public is to have confidence in the integrity of the courts,” commission Administrator Robert Tembeckjian said in a statement.

“It is an obvious and egregious conflict for a part-time judge to take action in a criminal case against the spouse of a client he is simultaneously representing in a related matrimonial matter.”

The office of Timothy Murphy, the lawyer who represented Katz in his case, declined to comment.