Jason Adams, right, the former Newtown Middle School teacher charged with bringing a gun to school, listens to his attorney John Maxwell during an appearance in state Superior Court in Danbury, Conn., on Sept. 22. (Carol Kaliff/Hearst Connecticut Media via AP)

For 10 years, Jason Adams taught eighth-grade science at a middle school just a couple of miles from Sandy Hook Elementary, the site of one of the worst school shootings in U.S. history.

A Newtown, Conn., native, Adams attended Sandy Hook as a boy. So did his son, who was in first grade and was not injured on the day a gunman wielding assault weapons shot and killed 20 children and six adults at the school.

So in April, when Adams brought a loaded .45 caliber pistol to his middle school, parents, teachers and administrators were alarmed and confused. A school employee told security he believed Adams, 46, was carrying a gun under his clothes. He was — and police arrested him for it.

Adams pleaded not guilty to a felony charge of possession of a weapon on school property and later resigned. For months, his reasons for bringing the pistol to the middle school were a mystery.

But on Thursday, Adams made himself clear.

During his sentencing hearing on the gun charge, Adams, who had a permit to carry the weapon, said he showed up armed because he and his family had received a barrage of threatening messages from Sandy Hook conspiracy theorists, ABC 7 reported.

“I’d move if I were you, you don’t want me anywhere near your town, I’m bad for people’s health – those are the types of threats that prompted him to renew his pistol permit,” his defense attorney John Maxwell said.

The judge seemed sympathetic, ABC 7 reported, saying he believed that Adams never intended to hurt anyone and that he would be unlikely to re-offend.

Adams, who admitted in the hearing to carrying the gun, was sentenced to accelerated rehabilitation, meaning the charge could be scrubbed from his record in a matter of months, according to the News-Times.

Almost four years have passed since 20-year-old Adam Lanza’s rampage through the Connecticut elementary school, but the Sandy Hook hoaxers still haven’t gone away.

It’s a small group of people who offer up a bevy of conspiracy theories about the mass shooting. The most prominent of their claims: that the December 2012 massacre was a “false flag” orchestrated by government officials to build support for gun control.

No credible evidence supports that theory — nor any of the others that have been peddled on message boards in dark corners of the Internet since the attack.

But that didn’t matter to the people who purportedly threatened Adams.

According to the News-Times, Adams began carrying a pistol when he started receiving dozens of threatening messages by phone and on social media from people claiming the shooting was staged.

Adams’s wife, Geri Adams, told the News-Times that many of the threats came from a New York man who created multiple social media profiles to continue the harassment.

In one message, the man told them to leave their home, she said. And in another, the man sent a picture of Geri Adams reading to a kindergarten class, along with the words, “Have fun reading to the dead children.”

“We did a background check and discovered the identity of the man,” she told the News-Times. “We brought all the information to the authorities, but the police never filed a report.”

Maxwell, Adams’s attorney, said Adams would keep the gun locked in his car during work. But on the day of his arrest, he was rushing to a staff meeting and he inadvertently brought it with him, he said.

Colleagues came to his defense when they heard the full story, Maxwell told ABC 7.

“He’s a great guy,” he said. “Good teacher, devoted, good family man, done right by everybody.”