FRESNO, Calif. (AP) _ A man with a history of mental illness burst into a packed courtroom Monday wielding two carving knives and was shot to death as he threatened a judge he may have blamed for his misfortune, authorities said.

Robert Eaton, 40, had an extensive arrest record and last year, rammed his car into the Merced County courthouse out of anger that he was refused treatment by a mental health facility, Merced County Sheriff Mark Pazin said. Merced is about 50 miles northwest of Fresno.

On Monday, Eaton drove back there in a Toyota Camry he hijacked from someone who was hired to take him to a doctor's appointment, Pazin said. He ran past guards and through a set of metal detectors at the front door holding a knife in each hand, he said.

As attorneys and witnesses cried out, Eaton charged through the doors of Courtroom 2 and into the well where lawyers were standing in the midst of court proceedings, Chief Deputy District Attorney Harold Nutt said.

"As soon as he hit the inside doors, I was behind him and I started yelling that he had a knife," said Nutt, who saw Eaton approach as he stood in the hallway talking with a colleague. "The officers started yelling at him, and yelling at everybody else to get down, and at that point it was rather chaotic. People started screaming, people started heading for the door, and I just ran back outside."

As Judge Brian McCabe tried to hurry his court clerks out of the courtroom through his chambers, Eaton held the knives aloft in a stabbing position about 30 feet away, Nutt said.

When Eaton refused to drop the weapons, several officers fired directly at him, and the man died on the courtroom floor, in front of a few dozen witnesses, law enforcement officers and others doing business in the court, Pazin said.

"There is a likelihood that he and Judge McCabe may have crossed paths in his courtroom," Pazin said Monday. "He had the knives in tow and literally left the vehicle running and came straight over to the courthouse."

Nutt said a public defender told him he recognized the suspect as a previous client with a history of mental illness.

Eaton had an arrest record dating back nearly two decades for car theft, vandalism and other charges, Pazin said.

No other injuries were immediately reported, but the courthouse was locked down for hours as investigators interviewed witnesses and officers involved in the incident, said sheriff's spokesman Tom MacKenzie.

Copyright 2008 The Associated Press.