A gay Bronx student who said he fatally stabbed a high-school classmate after years of being bullied was sentenced to 14 years in prison Tuesday.

Bronx Judge Michael Gross sentenced Abel Cedeno after a bench trial for the 2017 classroom killing at the now-closed Urban Assembly School for Wildlife Conservation. Mr. Cedeno, who is 20 years old, was found guilty of manslaughter, assault and a weapons charge on July 15.

The death of Mr. Cedeno’s classmate, 15-year-old Matthew McCree, was the first homicide in more than 20 years at a New York City public school.

Judge Gross acknowledged the context surrounding Mr. McCree’s death on Tuesday, calling his sentencing decision a difficult one.

“The death of this child should affect each of us profoundly,” Judge Gross told a packed courtroom in the Bronx, where Mr. Cedeno, his family and the families of his classmates were present.