OAKLAND, Calif. — A jury on Thursday acquitted one man of involuntary manslaughter but could not reach a verdict for the leader of an artists’ commune accused of turning a San Francisco Bay Area warehouse into a cluttered maze that trapped 36 partygoers during a fast-moving fire.

Jurors found Max Harris, 29, not guilty but said they could not unanimously agree on whether to convict or acquit Derick Almena, 49, of involuntary manslaughter after deliberating since Aug. 26.

The decisions follow an emotional three-month trial in which family and friends of the victims packed the courtroom.

“Jurors are hopelessly deadlocked. I must declare a mistrial,” Alameda County Superior Court Judge Trina Thompson said, sobs and gasps erupting from the section where families of the victims were seated.

Harris, who could have faced 39 years in prison, hugged his attorney after the first not-guilty verdict was read.

The December 2016 fire broke out during an electronic music party at a warehouse in Oakland called the Ghost Ship. The building was packed with furniture, extension cords and other flammable material, but had only two exits and no smoke detectors, fire alarms or sprinklers, prosecutors say.

The blaze killed 36, many of them young people trapped on the building’s illegally constructed second floor. Prosecutors said the victims received no warning and had little chance to escape down a narrow, ramshackle staircase.

Setbacks have riddled the criminal case against Almena and Harris.

The men were set to be sentenced last year to nine and six years in prison, respectively, after pleading no contest to manslaughter. But a judge threw out their pleas after many of the victims’ families objected, saying the proposed sentences were too lenient.

Last month, Thompson booted three jurors for misconduct and ordered the new jury to restart deliberations and disregard all past discussions. She reminded them they cannot talk to others about the case or seek outside information about it.

In closing arguments, Alameda County Deputy District Attorney Autrey James said the men didn’t obtain permits because they didn’t want inspections and they violated the fire code by refusing to install safety devices.

Almena was the master tenant and Harris acted like a manager by collecting rent and settling household disputes, the prosecutor said.

James told jurors that to find the men guilty of involuntary manslaughter, they must agree that their actions were criminally negligent. “Is failure to get a permit criminally negligent? Absolutely,” he said.

The defendants argued that city workers were to blame for not raising concerns about fire hazards and said the fire was arson. Investigators have never found what caused the fire, meaning arson cannot be ruled out.

Almena’s attorney, Tony Serra, repeatedly brought up instances in which fire, police and other officials toured the two-story building and never said anything about it posing a danger.