Remember back in August of 2008 when character actor Shelley Malil was arrested for the attempted murder of his ex-girlfriend, Kendra Beebe? You know what I’m talking about – he was accused of stabbing her 20 times? At the time it was said that he showed up at the mother of two’s house and went loco on her face, almost severing her chin.

Malil, who had a bit part in the hit movie 40 Year Old Virgin, is having his day in court now, and last Thursday testified that he stabbed Beebe by accident – he “wrongly thought that she was somebody else going after him in the dark.”

“I’m sorry,” Malil, 45, said in a Vista, Calif., courtroom. “I had no idea. I saw the pictures (of her wounds) 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.”

Taking the stand in his own defense, the actor insisted he never intended to kill or hurt Kendra Beebe, 38, at her San Diego County house one night in August 2008. But then “chaos” broke out, some of which he says he still can’t remember clearly.

Malil, who played one of Steve Carell’s electronics store coworkers in the movie, pleaded not guilty to charges of premeditated attempted murder, assault with a deadly weapon and residential burglary. He could get 21 years to life in prison if convicted. Beebe survived the attack and testified against him.

Malil told the jury that when he arrived at Beebe’s house, he found her sipping wine with her pal David Maldonado. Malil says he felt threatened because he thought Maldonado was about to come after him.

After a tumble, Malil says he realized Maldonado no longer had the knife. “I assume he’s going for something else,” he says. “I follow him to the kitchen.”

But on the way, Malil says Maldonado was headed to his car. “I’m almost positive this guy’s got a gun and coming after me,” he says. “I come around the corner. It’s eerily quiet. All of a sudden, out of nowhere, I get hit from the back on the side of the head. It felt like cold granite countertop.”

That’s when Malil, still carrying a knife at this point, started slashing out in defense in the dark. “It was going crazy,” he says. “It seemed like it was going for a minute.”

It wasn’t until hearing Beebe shout, “Call 911!” that Malil realized she was the one he was stabbing.

“That’s the first time I look and see it’s Kendra I’m fighting with,” he says.

The trial will continue with cross-examination Monday, and closing statements are expected Tuesday.