PASADENA, Calif.—A former Southern California high school teacher has pleaded no contest to murder in the 2008 slaying of a man who had been dating his ex-wife.

Prosecutors say Brandon Landreth entered his plea Tuesday to first-degree murder as well as admitting using a handgun to carry out the killing. The 33-year-old is expected to be sentenced to 35 years to life in state prison when he’s sentenced Feb. 22.

Landreth, a former teacher and chess coach at John Muir High School in Pasadena, was accused of fatally shooting Justo Cesar Morales in March 2008.

Authorities say Landreth’s former wife had been in a relationship with Morales during the year after she separated from Landreth.