Shelley Malil, the actor best known for playing an electronics store clerk in 'The 40-Year-Old Virgin,' testified Thursday that he stabbed his girlfriend 20 times by mistake. Malil said he thought Kendra Beebe was somebody else getting ready to attack him, PEOPLS reports.

"I'm sorry," Malil said in a Vista, Calif., courtroom. "I had no idea. I saw the pictures for the first time, I was stunned. When I look at those pictures, I still can't believe the knife I was holding was responsible for all those injuries."

The actor pleaded not guilty to charges of premeditated attempted murder, assault with a deadly weapon and residential burglary. Malil is facing a possible life sentence.

Beebe was stabbed at her San Diego County home in August 2008 after Malil found her socializing with another man, David Maldonado.