VENTURA, Calif. - A Southern California teenager was sentenced Monday to 21 years in state prison for killing a gay junior high school student during a computer-lab class, capping an emotional and tumultuous case that focused attention on how schools deal with sexual-identity issues.

Brandon McInerney was sentenced under terms of a plea agreement calling for him to report to prison next month, after he turns 18. McInerney, dressed in a white T-shirt and blue pants, did not speak at the hearing. His attorney, Scott Wippert, said his client was sorry for killing 15-year-old Larry King.

"He feels deeply remorseful and stated repeatedly if he could go back and take back what he did, he would do it in a heartbeat," Wippert said.

McInerney pleaded guilty to second-degree murder, voluntary manslaughter, and unlawful use of a firearm. A mistrial was declared in September when jurors could not reach a unanimous decision on the degree of guilt.

Several jurors said afterward that they did not think McInerney should have been tried as an adult.

McInerney had just turned 14 when he shot King at E.O. Green Junior High School in Oxnard. Prosecutors alleged the crime was the result of a homophobic rage spurred by King's feminine clothing and unwanted sexual advances toward McInerney.

The killing became a flash point for gay-rights groups, who said it was further evidence that children often pay a horrible price when they come out.

Comic Ellen DeGeneres, a lesbian, weighed in on her talk show and said gays should not be treated as second-class citizens.