I spent almost 13 years as a judge in Brooklyn, Queens and the Bronx. I supervised judges presiding over a wide spectrum of cases, dealing with complex legal issues, angry victims, difficult defendants and intense media scrutiny. The job can at times be thankless and frustrating.

But for all the cases I saw, I never encountered anything remotely as challenging as what Justice Juan Merchan faced in his Manhattan courtroom while presiding over the first criminal trial of a former president. And since Donald Trump was found guilty on 34 counts, Justice Merchan has come under further vicious attack.

As a retiree, I was able to attend each day of the Trump trial. What I saw was a master class in what a judge should be — how one can serve fairly and impartially for the prosecution and the defense, and above all remain a pillar for the rule of law in America.

Since the indictment over the cover-up of hush-money payments was issued last year, Justice Merchan has been subjected to an unrelenting pressure campaign. The defendant, Mr. Trump, and his supporters viciously attacked the judge and his family in deeply personal terms. Most judges strive to maintain their composure under the greatest of stress, but few succeed — yet Justice Merchan remained cool, calm and collected at every step of the trial.

As a supervising judge, I always emphasized the importance of maintaining control to those under my charge. That is how a judge ensures that all defendants — especially the most difficult ones — get a fair trial. That is how everyone is treated with courtesy and how rulings are evenhanded and fair. In this area, Justice Merchan excelled.

He issued a gag order carefully designed to protect witnesses, jurors, prosecutors and court staff, but left himself out of the order. He did this to ensure that the defendant’s right to harshly criticize the proceedings was protected even though he must have known that he would become an even greater target of Mr. Trump’s ire. When Mr. Trump repeatedly violated the order, Justice Merchan bent over backward to avoid sending the defendant to jail, despite a clear legal justification to do so.