FARGO, N.D. — A man accused of brandishing a gun in a North Dakota courtroom was convicted Thursday of two counts of attempted murder involving the sheriff and prosecutor.

Vicente Chacano, a Chilean native who was working in southwest North Dakota as a farmhand, was acquitted on 12 other counts involving jurors. He was accused of bringing a 9 mm semi-automatic handgun into the Adams County Courthouse in Hettinger on Feb. 4, 2011. Prosecutors said Chacano pulled the trigger several times, but the gun never fired.

The case, along with an incident in Minnesota in which a prosecutor was shot and wounded, sparked demands for heightened security in small-town courthouses. Officials say only a handful of courthouses in the two states use metal detectors on a regular basis.

Chacano told jurors Wednesday that he forgot the weapon was in his pants when he went to court to be sentenced after being found guilty of child molestation. Chacano was subdued by Assistant Attorney General Jonathan Byers, the prosecutor at the time, and Eugene Molbert, the county sheriff.

Chacano testified that he panicked when he realized he had the gun. He said he tried to leave the courtroom and blacked out.

During deliberations, jurors had asked Judge Steven McCullough if they could review transcripts of testimony by Byers and Molbert.

Prosecutor Brian Grosinger said in his closing argument Wednesday that Chacano's explanation about the gun and the 38 bullets he was also carrying was beyond belief.

"He didn't need all 38 to take care of Mr. Byers," Grosinger said.

Defense attorney Rob Quick told jurors the incident happened so fast that witnesses confused perception with reality. He said Chacano had no intent to hurt anybody.

"They jumped to the only conclusion they could think of in that setting," Quick said.