The two men accused of turning an Oakland, California, warehouse into a death trap where 36 people died during a 2016 rave escaped criminal punishment on Thursday.

Jurors deliberating since Aug. 26 found Max Harris, 29, not guilty of 36 counts of involuntary manslaughter and couldn’t agree on whether to convict Derick Almena, 49, of the same charges.

“Jurors are hopelessly deadlocked. I must declare a mistrial,” Alameda County Superior Court Judge Trina Thompson said, as families of the victims erupted into gasps and sobs.

Harris, the self-described “creative director” of the “Ghost Ship” arts collective, would have faced 39 years in prison had he been convicted.

He and Almena, the property manager and leaseholder, were charged roughly six months after a deadly blaze tore through the two-story illegally converted warehouse during a Friday night party in December 2016.

Furniture, extension cords and other flammable materials were packed inside the building, trapping partygoers who struggled to escape the second floor via a narrow, ramshackle staircase.

The building had no smoke detectors, fire alarms or sprinklers, and only two exits.

Alameda County Deputy District Attorney Autrey James said the men violated fire codes by refusing to install safety devices and didn’t obtain permits for the space because they didn’t want any inspections.

To find them guilty, the jurors had to agree that the men acted negligently.

“Is failure to get a permit criminally negligent? Absolutely,” James said.

The defense argued city workers were at fault for never raising an alarm about the shoddy space being a fire hazard.

Investigators have never found what caused the fire — and the defense said it could have been arson.

Almena testified that he felt remorse for having built the artist enclave.

“I built something. I dreamed something, I invited, I attracted beautiful people into my space, and I’m responsible for having this idea,” he said.

Meanwhile, Harris rejected the space’s characterization as a “death trap,” describing it as free-flowing commune where all the tenants built or furnished their areas as they saw fit.

“I would have made sure my friends were not buried there,” he testified.

The men were supposed to be sentenced last year to nine and six years in prison, respectively, after pleading no contest to manslaughter.

But a judge threw their pleas out after many victims’ families said the sentences were too lenient.

With Post wires