A Glenside man who punched a Philadelphia police officer during a November 2018 counterprotest of a white nationalist rally on Independence Mall was ordered by a federal judge on Wednesday to write “a sincere letter of apology” to the officer, but spared him from prison or probation.

Brian Glantz, 25, pleaded guilty to simple assault in December and could have faced a maximum sentence of one year in prison, five years’ probation, and a $100,000 fine for slugging Capt. John O’Hanlon.

But after nearly a two-hour hearing, U.S. Magistrate Judge Lynne A. Sitarski said the two days Glantz spent in federal detention after his arrest and the 19 months he’s been under court supervision awaiting sentencing was enough punishment.

She said that Glantz had taken responsibility for his crimes by pleading guilty, that he was a first-time offender, and that he is receiving treatment for autism and attention deficit hyperactivity disorder, which contributed to his impulsive behavior.

“While the offense was certainly a serious one, the defendant struck a law enforcement officer performing an important law enforcement function of attempting to keep the peace in an extremely volatile environment, the defendant has acknowledged the seriousness of the offense and has accepted responsibility,” the judge said during a video hearing.

Glantz, a Temple University film and media arts student, was one of four people charged in the aftermath of the 2018 clash between 50 “We the People” white nationalists and 500 counterprotesters, including Glantz.

Prosecutors said Glantz pushed on-duty officers at the rally and punched O’Hanlon in the side of his head.

As he was taken into custody, prosecutors said, Glantz resisted and kicked the officers.

Assistant U.S. Attorney Christopher Diviny did not seek a prison sentence but argued that Glantz’s actions warranted a probationary sentence to ensure he gets the medical treatment his lawyer and doctor testified that he needs.

“I, the government, and I think this court has the obligation to look at the totality of the circumstances,” said Diviny, who played a profanity-laced speech Glantz made at the rally to show that he was not as peace-loving as his lawyer portrayed him.

“Mr. Glantz is the one who went into that phalanx of police and struck Captain O’Hanlon in the face,” Diviny told the judge.

Defense attorney Susan M. Lin argued that her client was passionate about standing up to the white nationalists, not clashing with police, and only interfered with police because he believed the officer was beating an anti-white nationalist protester with a baton.

The rally was one month after a white, anti-Semitic gunman killed 11 at a Pittsburgh synagogue, and 13 months after a white supremacist drove his car into a crowd of protesters in Charlottesville, Va., killing a woman.

Lin said Glantz had those crimes in mind as he went to the Independence Hall protest to film the event and to speak out against the hate the “We the People” group was espousing.

“Brian did not go there to start anything. He saw somebody being hurt and he tried to help that person,” Lin said. “He interfered when he shouldn’t have interfered, and he understands that now.”

Glantz, choking back tears, apologized to his parents, who he said always taught him to respect the law, and to O’Hanlon and all the officers at the rally. “I acted impulsively,” he said. “I had no intention of hurting anyone. I know Captain O’Hanlon was just trying to do his job.”