Former University of Maryland student Alexander G. Song II, who wrote online posts threatening a shooting rampage on campus, pleaded guilty Tuesday to disturbing school operations and telephone misuse.

A former University of Maryland student who wrote online posts threatening a shooting rampage on campus pleaded guilty Tuesday to disturbing school operations and telephone misuse.

Dressed in a black suit with a solid-blue tie, 19-year-old Alexander G. Song II answered District Court Judge Patrice E. Lewis’s questions with little more than a “Yes, your honor,” or “No, your honor,” at the minutes-long hearing.

Lewis eventually took Song off home detention but ordered that he continue to receive ­mental-health care and abide by a 9 p.m. curfew while he awaits sentencing. At that time, prosecutors plan to ask that Song spend three years on supervised probation, authorities said.

“We think we have had an opportunity to avert what could have been a very tragic situation,” Prince George’s County State’s Attorney Angela Alsobrooks said after the hearing.

As part of his plea, Song admitted that he made multiple online postings in March threatening a shooting rampage at U-Md., where he was then a student. In one posting, he warned classmates, “Don’t go around 1 o’clock to the mall,” a major thoroughfare on the College Park campus, Assistant State’s Attorney Michael Glynn said in court.

But it remains unclear how serious the threats were and how capable Song was of carrying them out. Glynn said police found that Song had no weapons after officers searched his dorm room, his car and his family’s home.

Alsobrooks said that because Song pleaded guilty to telephone misuse — a crime that carries a three-year maximum sentence — he will not be allowed to carry a firearm, a factor that she called “critically important” in arranging the plea deal.

She said that although investigators did not find that Song possessed or tried to obtain any weapons, his online posts demonstrated “perhaps the beginning of behavior that would have escalated.” She said that a week before the threats were posted, the young man had demonstrated signs of a “mental breakdown.”

In court, Lewis and prosecutors seemed to treat Song more as a teenager in need of mental-health care rather than as someone who had threatened a shooting rampage. At one point, the judge told Song, “You look like you’re feeling much better than when I first saw you.” Cracking a slight smile, he responded, “Yes, your honor, I am.” Song and his defense attorney, Steven B. Vinick, declined to comment after the hearing.

Song’s next court appearance is scheduled for Sept. 13. Lewis ordered him to check in once a week with a case worker until then and start working on 200 hours of community service — which prosecutors had requested as part of his sentence.

“So far, reports have been fine,” Lewis told Song. “You’ve been accountable.”

Song, who lives in Fulton, withdrew from U-Md. in the spring, a university spokesman said. Were he to re-enroll, he would have to go through the university’s own judicial process for possible discipline, the spokesman said.