When a 17-year-old defendant denied throwing away drugs in view of police, Buffalo City Judge James A. McLeod offered an acerbic reply.

“Don’t play me like I’m stupid. You’re not bright enough to outsmart me,” McLeod said.

And then the court appearance turned ugly, as the defendant used foul language, laced with racial slurs, as he fumed at the 13-year veteran judge.

The judge replied in kind, and that has prompted the New York State Commission on Judicial Conduct to admonish McLeod for his discourteous conduct.

What’s more, while making his intemperate remarks, McLeod “ignored fundamental due process by convicting the defendant without a plea or allocution.”

The commission can admonish, censure or remove a judge for misconduct. Censure is a public reprimand, and an admonition is a milder public reprimand or warning.

After being sentenced to 15 days in jail for disorderly conduct, the defendant unleashed a verbal tirade, using vulgar words 11 times in a 33-word response to the judge.

When the defendant made a vulgar reference to his private parts at the Feb. 16, 2011, hearing, the judge replied, “Why don’t you pull it out for me.”

“Probably need a magnifying glass, too,” the judge said, when the defendant said he would were he not in handcuffs.

“Even in the face of provocative, disrespectful comments by a litigant, a judge is required to be an exemplar of decorum and dignity in the courtroom and not allow the proceedings to devolve into an undignified exchange of taunts, insults and obscenities,” the commission said in its finding.

The commission noted that McLeod’s improper comments were limited to a single occasion. McLeod has not been previously disciplined for judicial misconduct in his 13 years as a City Court judge.

Neither McLeod nor his attorney, Michael M. Mohun, could be reached to comment Wednesday.

The commission said McLeod has acknowledged failing to act in a proper manner. And the judge has accepted full responsibility, the commission said, for failing to maintain a high standard of conduct when he spoke to the defendant in the undignified and discourteous way.

“Even when baited by a disrespectful and profane party, a judge must remain patient, dignified and courteous, refrain from and not escalate the disrespect and profanity directed toward the court and maintain … the decorum of the courtroom,” the commission said.

McLeod stipulated and agreed to the facts of the case in the commission’s finding, which it recently made public.

The defendant appeared before the judge in two cases.

In one case, the defendant was charged with harassment and trespassing stemming from a Feb. 4, 2011, incident.

The judge characterized the harassment charge as “thuggery.” McLeod asked him if he knew what that meant. The defendant said he did not.

“It means being a bully, trying to impress people,” the judge said. “That’s not good, especially when they say you can’t follow through on any of those wolf cries. If they were to gang up on you, you would be the first one yelling mama as you’re running home.”

As for the trespassing charge, McLeod asked the defendant, “What’s going on with you over there, Mr. Tough Guy?’ ”

Without allowing the defendant to enter a plea, the judge convicted him of trespass and sentenced him to 75 hours of community service.

In the other case, the defendant faced two misdemeanors: a drug possession charge and obstructing governmental administration.

Without allowing him to plead guilty, the judge convicted him of disorderly conduct and sentenced him to 15 days in jail. That’s when the vulgar exchange occurred.

While continuing to use improper language, McLeod agreed with defense attorney Daniel E. Barry Jr. to recuse himself from the case. The judge then vacated the conviction, set a trial date, and set bail or allowed release under supervision. A week later, the Probation Department approved release under supervision.