The California teenager who fatally shot his gay classmate in the back of the head will be spending 21 years in prison under a plea deal reached on Monday.

Brandon McInerney, who was 14 when he shot and killed Larry King will be sentenced to jail until he is 38 years old, according to a deal reached with Ventura County prosecutors

McInerney pleaded guilty to both second-degree murder and voluntary manslaughter and has admitted the use of a firearm in the killing, states a release by the Chief Deputy District Attorney.

McInerney had previously been tried for a charge of murder with a hate crime enhancement, however a deadlocked jury could not reach a verdict.

District Attorney, Gregory D. Totten said that McInerney will be housed in a juvenile facility until he is at least 18 years of age and will serve the entire 21 years without time off for good behavior. In total he will have remained in custody for 25 years.

Prosecutors say four days before the shooting on February 12, 2008, McInerney began telling his peers about his plans to shoot and kill King.

Without the knowledge of his father and grandfather, McInerney took a gun from his house and placed it in his book bag, prosecutors said.

During a computer lab at E.O Green Junior High School in Oxnard, where McInerney sat behind the victim, he approached King and shot him in the back of the head and then shot him again once King hit the ground.

The District Attorney said that he is “keenly aware that many in the community feel that McInerney should have been tried as a juvenile,” but said the juvenile system was not able to address both the gravity of the crime and the need for public safety.

“The McInerney case has resulted in strong and unprecedented emotional and philosophic outpourings, both in the community as well as the trial jury,” Totten said, calling the case strong, powerful and emotional.

Totten said King “faced challenges in his young life at least as severe as those of the defendant.”

“As the victim began to explore his sexual identity, he was ostracized and ridiculed by many of his classmates,” he said.

“There was no evidence that he inappropriately touched, “bullied” or harmed anyone…there was no justification for the use of a deadly force.”

McInerney is scheduled to be formally sentenced on December 19.