David Paradiso was shot after he left the witness stand and began attacking San Joaquin County Superior Court Judge Cinda Fox during a break in proceedings, said Karen McConnell, a county spokeswoman.
McConnell said Paradiso had been testifying about 2 p.m. when his mother, in the audience, left the courtroom upset. Fox called a recess, and as jurors filed out, Paradiso left the stand and approached the judge from behind, she said.
McConnell said witnesses reported seeing Paradiso lift the judge and begin punching and possibly stabbing her when bailiffs ran to her aid and shots rang out. It was not immediately clear who shot Paradiso.
The Stockton Record, which was covering the trial, reported that the judge was carried out on a stretcher and had bandages on one arm but was conscious and alert.
The courthouse immediately went on lockdown, McConnell said.
Paradiso was on trial for allegedly stabbing his girlfriend in the neck in his mother's car in 2006.
His attorney, Charles Pacheco, did not immediately return a call seeking comment.
ABC affiliate KXTV reports Judge Fox is the same judge presiding over the case of the alleged torture of a teenager in Tracy. The two cases are unrelated.
ABC7 contributed to this report.