A 26-year-old convicted sex offender admitted Tuesday that he made online racist threats against Howard University students from a Panera Bread restaurant in Virginia in the fall of 2015.

John Edgar Rust left messages on 4chan and Reddit using the n-word to say that any blacks “left at Howard University after 10 tomorrow will be the first to go . . . After all, it’s not murder if they’re black.”

He also wrote, “I’ll go out a hero knowing I made the world better.”

The threat was taken seriously, with city and campus police stepping up their patrols around Howard for two days after the messages were posted online. Some classes were canceled, and parents and students expressed concern that the campus was not locked down.

In court Tuesday, public defender Maria Jacob said her client was struggling with mental-health issues but that they did not affect his competency.

Rust is a sex offender who was on probation and barred from using the Internet at the time he made the threats. His 2012 conviction stems from an incident involving a child in Loudoun County, according to court records.

John Edgar Rust is shown in this photo from the Virginia State Police Sex Offender and Crimes Against Minors Registry. (N/A/VSP)

Prosecutors say they were able to identify Rust because a MacBook Air and Nokia phone registered under his name were both connected to Panera’s WiFi network the day of the threat, and his credit card had been used at the restaurant.

He initially denied making the threats, according to an FBI agent’s report, telling law enforcement he used the Internet only to look for work and check his email. Later he told his probation officer he went on Reddit only to look at cat videos and had used the Panera WiFi to talk to his girlfriend.

When they searched his computer, law enforcement found drafts of the violent, racist message.

Threats against schools appear to be on the rise in the wake of the shooting at Marjory Stoneman Douglas High School in Florida that left 17 people dead. In federal court, the maximum sentence for making such threats is five years.

Rust will be sentenced July 20.