Brandon McInerney has pleaded guilty to the second-degree murder of gay classmate Larry King, and faces 21 years in prison for lesser charges as part of a plea deal.

McInerney was 14 when he shot King in the back of the head during a lesson in 2008.

McInerney had admitted killing King but denied murder. He had said King, 15, who self-identified as gay and wore feminine clothing, had teased and provoked him.

A mistrial had been declared in September of this year when jurors failed to reach a decision.

In a retrial, he admitted second-degree murder, voluntary manslaughter and use of a firearm.

The district attorney’s office in California said he would serve 11 years for voluntary manslaughter and 10 years for the use of a firearm, but will not serve time for the murder as part of a plea deal.

Larry King’s father, Greg King, told the KABC-TV station he understood the plea deal.

He said: “I don’t think that 21-year sentence is justice for my son, but I understand the reality that was facing the DA, of trying to convict a defendant who was 14 [...] when he committed the murder.

The prosecutor’s office said: “He will serve the entire 21 years without time off for good behaviour and will not receive time off his sentence for the three years and nine months he has spent in juvenile hall before sentencing.”

McInerney’s attorney Robyn Bramson told Reuters: “It’s very unorthodox. Both sides wanted to resolve it for various reasons, and this was just our way of getting to something that was tolerable for both sides.”

The sentence will be handed down on 19 December.