Fernando Salgado, 18, agreed to plead guilty to one count each of attempted sexual penetration by a foreign object and assault with a deadly weapon, said Christopher Lee, a spokesman for the San Bernardino County district attorney's office.
Salgado will be released from jail immediately in exchange for testifying against his teacher.
Superior Court Judge Douglas A. Fettel stayed Salgado's sentence of three years of felony probation and 180 days in county jail in exchange for his testimony. The teen could have faced four years in prison if convicted of both charges, Lee said.
Prosecutors say the teacher, 27-year-old Emmanuel De La Rosa, directed four students at A.B. Miller High School to assault other classmates. De La Rosa has pleaded not guilty to five felony counts, including attempted sexual penetration with a foreign object and false imprisonment. He'll be back in court later this month.
The Associated Press contributed to this report.