An upstate judge has resigned after a lawyer claimed that the jurist told him he should get a hotel room with actor Viggo Mortensen “and suck each other’s d–ks.”

LeRay Town Court Justice John W. Hallett allegedly made the crude comment to lawyer Terence Brennen — who was promoting a film festival honoring the “Lord of the Rings” movie star — in January 2017 at the Jefferson County Court Complex in Watertown.

“You and Viggo Mortensen should get a hotel room and suck each other’s d–ks,” Brennen claimed the judge said, according to a complaint with the state Commission on Judicial Conduct.

Hallett also allegedly told the lawyer that the film festival was “about the gayest thing I have ever heard,” according to the complaint.

Five months later, while speaking with Brennen again, Hallett allegedly made a gesture to “connote oral sex” and then patted the lawyer on the cheek, saying, “There, there, little boy,” the complaint says.

The commission hit Hallett with a formal written complaint in August, and the jurist has now agreed to step off the bench at the end of the year and never serve in any judicial capacity again, the commission announced Wednesday.

“Homophobic remarks and anti-LGBTQ sentiments have no place in the lexicon of the courts or the vocabulary of a judge,” the commission’s administrator, Robert H. Tembeckjian, said in a statement.

“Such statements undermine public confidence in the integrity and impartiality of the judiciary, which demands that a judge be and appear fair-minded and unprejudiced toward all who have business in the courts.”

Hallett has been the town’s court justice since 2003, and his current term was slated to wrap up at the end of next year.

Hallett declined to comment.