OAKLAND, Calif. — Two men charged in a California warehouse fire that killed 36 people agreed to a plea deal Tuesday during an emotional hearing where the judge read the name of each victim aloud, bringing tears from loved ones in the courtroom.

Under the terms of a plea agreement, Derick Almena and Max Harris each pleaded no contest to 36 counts of involuntary manslaughter involving the 2016 blaze at a dilapidated Oakland warehouse known as the “Ghost Ship” during an unlicensed concert.

Almena could be sentenced to nine years in prison and Harris could face a six-year term when a judge sentences them next month.

The men could have faced life in prison if convicted at a trial. Now, with good behavior, they are only expected to serve half their sentences after spending a year in jail.

David Gregory, whose 20-year-old daughter, Michela Gregory, was among the victims, said hearing the defendants say no contest was “some small sense of justice.” Still, he was dissatisfied with the outcome.

“That’s 36 lives, you know,” he said outside court. “We wanted fair justice, and we didn’t get it.”

Other family members declined comment.

Authorities say the 48-year-old Almena rented the warehouse and illegally converted it into an entertainment venue and residences before the fire. The 28-year-old Harris helped him collect rent and schedule concerts.

Prosecutors say the men turned the cluttered building into a “death trap” with few exits, rickety stairs and dark and dangerous passageways.

During Tuesday’s hearing, Alameda County Judge Morris Jacobson had the men say no contest as the name of each victim was read. The emotional process took 30 minutes, with family members and friends crying quietly when their loved ones were named.

Harris also cried as he pleaded “no contest” to each count. Almena answered “no contest” quietly 36 times.

Gregory said he and other families would have preferred a trial and sentences as long as life in prison. He cut off reporters’ questions when they asked how he felt when he heard his daughter’s name read in court.

Prosecutor Autrey James said the two men were convicted “because they acted negligently running that building known as the Ghost Ship.”

James declined to answer questions outside court, saying the case was still active until the men are formally sentenced.

Almena’s attorney Tony Serra said his client agreed to the plea bargain to alleviate “the pain and suffering of all parties.”

Serra previously said a plea deal would spare the victims’ families from testifying at a trial where photos of burned bodies and other emotionally fraught evidence would be shown.

Bureau of Alcohol, Tobacco and Firearms investigators said they could not determine the cause of the blaze.

A typical manslaughter case often results in shorter sentences, Stanford University law school professor Robert Weisberg said, citing a three-year sentence given to a transit officer in the region who mistook his gun for a stun gun and fatally shot a passenger.

‘On the other hand, there were 36 victims,” Weisberg said about the warehouse fire. “This was a manslaughter case that felt like a murder case.”

Almena lived in the warehouse with his wife and three children. The family was staying in a nearby hotel on the night of the fire. Harris also lived in the warehouse and escaped the fire unharmed.

The city of Oakland and the warehouse owner Chor Ng are being sued by the families for wrongful death.

Ng, who has not been charged criminally, didn’t return a phone call Tuesday.