A New York City teacher who was fired after he showed up for jury duty with heroin in his possession had his termination overturned by a judge, who called the punishment “excessive.”

Damian Esteban, a teacher at the Williamsburg High School for Architecture and Design in Brooklyn, and a recovering drug addict, arrived at Manhattan Criminal Court last year with the heroin hidden in a pack of cigarettes.

Esteban told a judge he had taken the wrong backpack with him to jury duty. He went to a one-day treatment program, and misdemeanor criminal charges against him were dropped.

But the teacher was still fired by the city. Esteban sued to get his job back, and Manhattan Supreme Court Judge Manuel Mendez agreed with the canned teacher in a ruling Thursday, according to the New York Daily News.

In his ruling, Mendez said the firing was “excessive and shocking to this court’s sense of fairness.” The Associated Press added that Mendez said Esteban’s canning was “unduly harsh.”

Esteban should have been suspended without pay instead of fired, the judge ruled.

The ruling did not sit well with New York City Mayor Michael Bloomberg.

“We could not disagree more strongly with the judge’s decision,” Bloomberg said, according to the Daily News.

The New York City Department of Education said Esteban, who did not tell his boss about his arrest, was causing “widespread negative publicity, ridicule [and] notoriety to the NYC Department of Education.”