Malil received a sentence of life in prison with a possibility of parole from a San Diego County Superior Court judge. Malil was sentenced in the city of Vista, near Oceanside.
Malil could be set free in nine years, according to the prosecutor in the case.
Malil was convicted in September of attempted premeditated murder and assault with a deadly weapon. He was acquitted of a burglary charge.
Malil is accused of attacking Kendra Beebe in her home in San Marcos in August 2008. He found her with another man and attacked her with a kitchen knife, stabbing her more than 20 times. Beebe survived the attack.
Malil had a role as a co-worker of Steve Carell's character in "The 40-Year-Old Virgin."
The Associated Press contributed to this report.