HAMILTON, N.J. – A middle school social studies teacher’s year-long fight for his job recently reached a settlement that will pay him more than $26,000 to resign and go away.

Officials in the Hamilton, New Jersey school district removed Crockett Middle School teacher Joseph Mahon from the classroom in 2013 after a psychiatrist found he had a “repeated use of substances that are not prescribed,” including sedatives, hypnotics or cocaine, which made his depression worsen, NJ.com reports.

His attorney denied the drug use, and argued school officials discriminated against Mahon in violation of the American with Disabilities Act by holding his “past psychiatric problems and drug use” against him.

MORE NEWS: Know These Before Moving From Cyprus To The UK

“He did have a positive marijuana test back in 2011 but, since then, has been continuously drug tested by the school system and hasn’t tested positive for anything – marijuana, cocaine or any illegal drugs,” Mahon’s lawyer, Ralph Gerstein told NJ.com.

“He’s been completely off illegal drugs for over three years.”

Mahon was required to attend a rehabilitation program in order to return to work, and was reinstated months later after two re-evaluations, though it’s unclear whether he actually went to rehab.

It was after his return that school officials contend Mahon showed a “complete lack of ability, effort and motivation to teach.” He also made numerous racist, sexist and homophobic remarks to students between Sept. 30, 2013 and Jan. 30, 2014 – when he was removed from the school a second time.

District officials filed tenure charges against him to permanently end his employment in August 2014.

The Trentonian secured Mahon’s records through a public information request:

In September 2013, a co-worker witnessed Mahon chuckling to himself while delivering a PowerPoint presentation regarding India, the charges read.

When asked by students why he was laughing, Mahon allegedly recalled an instance when he was with his daughter at a playground where she was playing with children — some of Indian descent.

“His daughter asked him what was that bad smell,” the charges state the teacher told his class. “Mr. Mahon responded to his daughter that all Indian people smell bad.”

Furthermore, other alleged inappropriate comments made by Mahon during instruction included “Koreans, Japanese and Asians are all Chinese,” “God is never wrong,” “Jews talk funny,” “all Hispanics are the same,” “a slave was never enslaved by a white man and that they sold each other,” and “the first thing of when you think of Islam is terrorists.” Additionally, in an apparent statement opposing gay marriage, he allegedly said, “If my son was gay, I would have an operation to remove that.”

MORE NEWS: How to prepare for face-to-face classes

District officials also allege in the tenure charges that Mahon tested positive for cocaine in 2012, and that his “abnormally elevated mood” was the product of “cocaine-inhaled, once a week for 10 years,” according to the site.

Gerstein attempted to explain away Mahon’s off-the-wall comments to students, alleging they were taken out of context. He pointed out to NJ.com that his client had never been accused of racist, anti-Semitic or homophobic comments before the 2013-14 school year.

“From all the experience I’ve had with people who are racist or anti-Semitic, it doesn’t happen overnight,” Gerstein said. “If he really said the things he’s accused of, he’d have a long history of this.

“Being Jewish, if I thought he were anti-Semitic, I would not have taken the case,” he said.

District officials reached a settlement with Mahon on Dec. 11 that exchanged his letter of resignation for $26,875 – about half of his $54,309 annual salary. The district agreed to drop the tenure charges as part of the deal, and Mahon is prevented from disparaging or suing the school district in the future, according to media reports.

The state could still seek to suspend or revoke Mahon’s teaching license, but the settlement also prohibits the district from making students available to testify against him, The Trentonian reports.