A gunman opened fire outside a crowded Pennsylvania courtroom Wednesday afternoon, shooting at police and others before an officer fired multiple shots at him, killing him.

Fayette County District Attorney Richard Bower said Wednesday evening that a German Township police officer shot and killed the gunman after he entered the lobby in Masontown with a handgun drawn and opened fire injuring four people. Bower declined to name the gunman, saying only that he was due in court on charges related to a recent domestic violence incident.

Bower said Masontown police Sgt. R. Scott Miller first encountered the gunman and was injured when he exchanged gunfire with the shooter. When Miller took cover, Bower said the gunman proceeded to fire shots injuring two men and one woman.

"In this case, as is so often the case, the German Township police officer ran toward the danger, not away. He protected over 30 to 40 people from injury or death," Bower said.

"These police officers and these emergency management people risk their lives every day ... and today they all were a shining light to our community," he added.

Bower declined to say whether any of the civilian victims were related to the domestic violence allegations. He said the gunman was facing charges of strangulation, aggravated assault, terroristic threats and simple assault. He said there was a protection of abuse order against the gunman in the strangulation case.

A Fayette County 911 center supervisor confirmed the three civilian victims were taken to the Ruby Memorial Hospital in Morgantown, West Virginia, for treatment. Amy Johns, public affairs director at the hospital, said late Wednesday they had received a 47-year-old male, 35-year-old male and 39-year-old female from the shooting and all were in fair condition as of about 5:45 p.m.

Masontown Mayor Toni Petrus was at the hospital Wednesday afternoon checking on Sgt. Miller. She said he was in good condition and was being treated for non-life-threatening injuries.

State Police troop commander Lt. Steven C. Dowlin said that even though the shooting happened near the office of District Judge Daniel Shimshock, neither he nor his staff appeared to be the intended target of the shooter.

Dowlin said the judge, assistant district attorneys, lawyers, police officers and others were in the courtroom near the lobby when shots were fired.

Joyce Royster was in the courtroom at the building Wednesday. She told WTAE there were dozens of people inside the courtroom when the shooting started just outside. She said people fled the courtroom as the shooter started to move inside and took shelter in offices and other courtrooms.

Dowlin said this is the second mass shooting that state police have responded to in Fayette County this year. He said troopers stopped a young individual at a Uniontown High School from carrying out a shooting.