A man who was supposed to be returning divorce papers at a courthouse pulled out a gun there instead Wednesday, opening fire in the lobby before two bailiffs fatally shot him.

Several people were in the lobby at the time, but only one of the bailiffs, who was shot in the shoulder, was injured. He was treated and released from a hospital.

Glen Lee Powell, 30, entered the courthouse shortly after 1 p.m. and approached a security checkpoint wearing a backpack. A deputy ordered him to remove the backpack and place it on a conveyor belt, but instead he threw it on the ground and opened fire with a semiautomatic handgun, Pinellas County Sheriff's Sgt. Jim Bordner said.

Deputies B.J. Lyons and Deputy Marvin Glover returned fire, seriously wounding Powell, who later died at a St. Petersburg hospital. Lyons, a 58-year-old firearms instructor, was wounded.

A representative speaking for Powell's family said he had been living with his parents after returning from duty in the Air Force in California.

Bishop David Scott of the Brandon ward of The Church of Jesus Christ of Latter-day Saints, which Powell attended, said Powell was returning divorce papers due at the courthouse Wednesday.

Detectives were working to determine a motive, Bordner said. He said Powell's wife is safe and had been notified of his death.

Scott said the man's parents did not know he had a gun and had no indication Powell was troubled.

"They weren't aware that he was contemplating this," Scott said. "We don't really understand why it happened."

He added that Powell hadn't been upset about the divorce.

Scott said Powell had done a two-year stint as a Mormon missionary in Colombia at his own expense before joining the Air Force.

The gunfight unfolded as court staffers and a handful of others were in the lobby of the courthouse, which has about 70 employees.

Pinellas County Clerk of Court Ken Burke said one of his office windows was shattered by a bullet. None of the clerk's staff was hurt, but he said a worker had just emerged from the elevator when the gunshots erupted.

The courthouse was closed after the shooting and is expected to resume normal business on Thursday.

Court officials credited the bailiffs with averting a tragedy.

"It's unfortunate that a life was lost, but the public, employees, judges and others in (the) courthouse were properly protected," said Judge Robert Morris, the chief judge of Florida's Sixth Judicial Circuit.

Cassandra Grady, 40, and her 15-year-old daughter went to the courthouse Wednesday for a hearing and saw the man before the shooting. Grady told the St. Petersburg Times the man asked her where he could file a petition, and that she saw a gun handle in his backpack.

"I told my daughter, 'Run for your life.' Then I started running. I was trying to run to warn them. He started shooting. I heard a round of shots: pop-pop-pop, pop-pop-pop."

Grady was shaken but grateful. "I just want to say, 'Thank you, God.' It could have been us."

Click here for more from MyFOXTampaBay.com.