A 16-year-old student who told the authorities that he was bullied because he was transgender pleaded guilty on Friday to first-degree murder in a school shooting outside Denver last year that killed one student and injured eight.

The student, Alec McKinney, also pleaded guilty in Douglas County District Court to 16 other counts in the attack, which prosecutors say he carried out with another student, Devon Erickson, 19, at the STEM School Highlands Ranch on May 7, 2019.

The shooting, in an English class that was watching “The Princess Bride” three days before the last day of school, killed Kendrick Castillo, 18, a gentle teenager fascinated by cars and engineering who classmates said lunged to try to stop the attack.

Mr. McKinney is scheduled to be sentenced on May 18.

Under Colorado state law, the mandatory minimum sentence for a 16-year-old convicted of first-degree murder is life with the possibility of parole after 40 years minus earned time. If Mr. McKinney were to be accepted into a special program for prisoners under 18, he could be released within 20 or 25 years, said Vikki Migoya, a spokeswoman for the district attorney for the 18th Judicial District, which includes Douglas County.