Brandon McInerney, left, has pleaded guilty to shooting his gay classmate, Lawrence "Larry" King to death in February 2008, when McInerney was 14 and King was 15.

More than three years after he pulled out a gun in a junior high computer lab and shot classmate Larry King in the head, Brandon McInerney pleaded guilty on Monday to second-degree murder. Sentencing is set for sometime in December, and prosecutors have said McInerney will be sentenced to 21 years in prison, without time off for good behavior, according to MSNBC.com.

McInerney has already served four years in jail and will be 38 by the time he is released.

The plea deal comes after prosecutors’ first efforts to convict McInerney on murder and hate crime charges in July ended in a mistrial. In planning for a second trial, prosecutors had decided to drop the hate crimes charge because jurors in the first trial did not believe prosecutors’ charges that McInerney was a white supremacist who acted out of hatred for gays.

King, 15 at the time of his death, was an openly gay student at E.O. Green Junior High in Oxnard, Calif., and McInerney, 14 at the time, was angry that King had been flirting with him. On Feb. 12, 2008, McInerney carried a gun to school in his backpack. When he went into the computer lab, he walked up behind King, shot him once in the head and then shot him again as King lay on the floor. King died two days later after being taken off life support.

The murder sparked headlines and outrage around the country. But when McInerney went to trial in July, his defense attorneys denied that he had been motivated by anti-gay hatred and worked to convince jurors the school was at fault for not reining in King’s flamboyant behavior in class. And on Monday, King’s mother, Dawn King, told the LA Times that she had contacted the school four days before the shooting to ask for school officials’ help in “toning down” her son’s behavior. She said school officials told her that her son had a civil right to explore his sexuality.

Authorities had removed Larry King from his home two months earlier because of domestic problems.

Teachers at E.O. Green Junior High also testified at McInerney’s trial in July that they had tried to warn administrators about “growing tensions” between Larry King and some of the boys in his class, but that the administrators had “shunned them.” The LA Times reports that teachers and students alike testified at the trial that King had been wearing makeup and women’s accessories and “flirting aggressively with male students on campus who did not want the attention.”

Following the mistrial in July, Gay, Lesbian, Straight Education Network Executive Director Eliza Byard said prosecutors should have “done the just and merciful thing” and reached a plea agreement with McInenery because the trial created a “painful spectacle that accomplished nothing.”

Following Monday’s announcement that a plea arrangement had been reached, Byard said:

“The plea deal announced today ends a tragic chapter in Ventura County. Holding Brandon McInerney accountable for his actions is necessary and right, but putting him behind bars does not solve the problems that led a boy to become a bully, and then a murderer.  Homophobia and transphobia, compounded by the lack of counseling and other supports for struggling young people, resulted in Larry King’s death and the effective end of Brandon McInerney’s life. As adults and as a society, we must find the resolve to fix the broken systems that lost two young lives to hate and fear. The end to this painful chapter must now serve as a new beginning. Ventura County along with communities and school districts everywhere must come together to promote a culture of respect and nurture the true potential found in every individual regardless of sexual orientation, gender identity, or gender expression.”