Former Army Ranger Gary Smith was sentenced to 28 years in prison Monday in the 2006 shooting death of his roommate and fellow Ranger Michael McQueen, a decision that surprised both men’s families and brought promises of appeals from Smith’s attorneys.

“It’s better than we thought,” said McQueen’s mother, Glenda.

“It’s unbelievable,” said Smith’s grandfather Gary Smith.

Both sides expected Smith to be given a shorter sentence after a Montgomery County Circuit Court jury found him guilty last month of involuntary manslaughter but acquitted him on a murder charge. He was given 10 years on the manslaughter conviction and 18 years for using a handgun in the commission of a felony.

Shortly before he was sentenced, Smith stood before Circuit Court Judge Eric M. Johnson, and — limited by attorneys worried about future appeals — made a halting statement of regret to McQueen’s family.

Gary Smith, bottom; Michael McQueen, above.

“I’m sorry for their pain. I wish they didn’t feel it. I wish there was something I could do to somehow make it better,” he said.

Johnson, acknowledging statements of support from Smith’s family and friends, said Smith had served his country honorably.

But, he said, “when good people do bad things, they have to be held accountable.”

Smith was convicted in 2008 of a type of a second-degree murder, known as depraved-heart murder, and a gun charge. He was sentenced to 35 years. That conviction was overturned, and his second trial concluded last month. Jurors in the second trial were sharply divided on the murder charge, and said they compromised on the lesser manslaughter charge rather than have a hung jury.

Prosecutors argued in both trials that Smith put a gun to McQueen’s head and pulled the trigger, while defense attorneys said McQueen killed himself, either on purpose or by accident.

Smith told detectives that he brought a gun to the men’s apartment, loaded it in the parking lot, took it upstairs and put it near McQueen. Smith told them that when he emerged from the bathroom, he came into the living room as McQueen was shooting himself.

Smith was granted a retrial when Maryland’s highest court threw out his conviction last year because the original jury was not allowed to hear testimony about McQueen’s state of mind.

But after all the years of legal wrangling — and a 12-day retrial rehashing Smith’s actions and the gruesome Gaithersburg scene where McQueen was found dead — Johnson gave Smith a sentence that was just seven years shorter than he had handed down in 2008.

Smith did not testify during his trials. Last month, jurors watched a video recording of Smith being interrogated for hours by detectives.

Johnson said the way Smith behaved after McQueen’s death did not square with what one would expect if Smith had seen McQueen kill himself. When a detective first raised the idea of suicide, Johnson recalled, Smith “said, ‘Yeah, that’s it, he killed himself.’ ”

“Your behavior can be best described as an inappropriate affect,” Johnson said. “Your affect was rather flat.”

Prosecutors and defense lawyers sparred Monday over whether Johnson should, or could, give Smith more than five years for the gun charge. Smith was sentenced to 20 years, with all but five years suspended, on that charge in 2008, and defense attorneys said five years was the ceiling.

But Johnson sentenced Smith to 20 years for the gun charge, suspending only two. He said Smith’s conduct since the earlier sentence justified the new number. That conduct included having possession of a homemade knife and making wine while in prison, he said.

The sentence for manslaughter was 10 years. Smith was given credit of nearly six years for time served, so the remaining sentence is about 22 years.

“This is an enormously hard-fought win,” said county State’s Attorney John McCarthy. “It’s an appropriate and fair sentence.”

Defense attorneys said Smith’s life had been threatened in prison, and he was moved to another facility for his safety.

“It was a shocking departure from what we expected the law to be,” said Barry Helfand, one of Smith’s attorneys.

The case will be appealed, the attorneys said. “I think this case is a sure-fire bet to be back for a third time,” Helfand said.