ELIZABETH -- A Superior Court judge Friday sentenced a Kean University graduate to 90 days in jail and five years probation for posting Twitter messages threatening to kill black students on the campus.

However, Judge Robert Mega expressed his disagreement with the plea-agreement and sentence for the defendant, Kayla McKelvey, an African American woman, who admitted writing the messages because she wanted to bring attention to racism on campus.

In her statement to the judge, McKelvey apologized for sending the messages, which said black students would be shot. She admitted the tweets were wrong but said her intent to raise awareness about racial issues was correct.

McKelvey, 25, and a former president of the university's Pan African Student Union, said she "made a poor error in judgement to shine a light on an issue that is important to me. My intent was to expose racism on campus," McKelvey said. She opened her statement by apologizing to the university and Union Township police, and to her friends and family.

The messages were sent during a protest last November about racism on the campus. McKelvey in court today said that during the rally she heard "people yelling white power, calling us monkeys."

She had pleaded guilty to a charge of creating a false public alarm, and in exchange, the prosecutor's office agreed to recommend the three-month sentence.

Mega, before announcing the sentence, challenged Union County Assistant Prosecutor Shawn Barnes to defend the plea agreement.

"Why shouldn't I reject this plea," Mega asked. He said the threats caused mayhem on the campus and could have turned the university community "into a tinder box."

Twitter messages sent Nov. 17 threatening black students at Kean University.

Barnes replied that it was a third-degree crime, that McKelvey had no prior criminal record, that she agreed to pay $82,328 in restitution to law enforcement agencies that investigated the threats, and that the plea agreement had been discussed with Kean University.

McKelvey's lawyer, Thomas Ashley, had asked Mega to place his client on probation, with no jail time, saying McKelvey had been an honor student, a homecoming queen, a student leader on the campus prior to graduation in the spring of 2015, and had a history of community service.

Ashley said McKelvey once had a bright future but now has suffered, losing her job as a certified personal trainer, and losing nearly all her friends.

Barnes had previously argued for a three-month jail sentence, saying that Friday was the first time McKelvey had expressed remorse. He said the 10 threatening messages spread panic across the campus, and caused more than half of students to miss two or three days of classes, all because McKelvey wanted to attract more protesters to her rally.

"To say that these threats were made for the greater good is disingenuous. It was selfish. It was for her rally," Barnes said.

Mega, who also ordered that McKelvey serve five years probation after completing the jail sentence, called the threats "heinous," and repeatedly referred to McKelvey's claim that she did the wrong thing but for a good reason.

"They (the threats) created a sense of terror among the university society," Mega said.

Authorities say that on Nov. 17, 2015, McKelvey, then a graduate of the university, participated in a protest against racism on the campus.

McKelvey left the rally midway through, however, going to a computer station located in a university library and creating an anonymous Twitter account to post the tweets. She then returned to the rally and spread word of the threats.

After the sentence was announced, McKelvey was led away by sheriff's officers.

Tom Haydon may be reached at thaydon@njadvancemedia.com. Follow him on Twitter @Tom_HaydonSL. Find NJ.com on Facebook.