Larry King (L) and Brandon McInerney (R)
Larry King (L) and Brandon McInerney (R) Family handout

A teen from southern California who shot dead a 15-year-old gay classmate he believed was flirting with him has pleaded guilty to second-degree murder.

Brandon McInerney was 14 when he brought a handgun into E.O. Green Junior High School in Oxnard and shot classmate Larry King twice as he sat at a computer.

McInerney, now 17, admitted the murder charge, voluntary manslaughter and use of a firearm under a plea. He is set to spend the next 21 years in prison, serving 11 years for manslaughter and 10 years for the use of a firearm, according to the district attorney's office. His formal sentencing is set for December 19.

The plea follows a mistrial earlier this year when McInerney was tried for murder as an adult. Five jurors voted to convict him of murder while seven voted for manslaughter.

During the first trial, prosecutors tried to portray McInerney as a homophobe and a budding white supremacist who was enraged by King's sexuality and the way he dressed.

McInerney's attorneys had argued that King, who was openly gay, had made sexual advances against their client.

His lawyer did not try to deny that his client pulled the trigger and shot him in the back of the head and once more as he lay on the floor, but that the teenager had reached an emotional breaking point over these unwanted sexual advances.

Larry King's father, Greg King, told KABC-TV he understands why prosecutors agreed to the plea deal.

"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," Greg King 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," the prosecutor's office said, concluding that he'd then serve nearly 25 years total.

McInerney will not be sentenced for the second-degree murder charge.

"It's very unorthodox," McInerney's attorney Robyn Bramson said to Reuters. "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."