MEXICO CITY — At least 13 inmates died in a prison riot in northern Mexico that authorities ended with lethal force, a state security official said late Tuesday.

Spokesman Aldo Fasci said the riot occurred at the state prison in Cadereyta and the death toll could climb because eight people were in critical condition.

All afternoon Tuesday, desperate families battled authorities outside the prison gates, demanding information about their relatives inside as black smoke poured from several points inside the facility.

Several hours of attempted negotiations failed and police using non-lethal force were unable to quell the riot, Fasci said. So authorities decided to use lethal force to protect the lives of the guards and the prisoners.

Authorities could see through video monitors that at least one prisoner had already been killed and guards had been taken hostage, Fasci said. The guards were being held and beaten on the roof.

“If they had not taken these decisions right now, we would be talking about many more dead,” Fasci said.

The trouble started Monday night when one of the half-dozen gangs that are normally kept apart inside the prison protested. The protest died down, but early Tuesday, fighting broke out and a prisoner was killed and his body burned, Fasci said.

When police first went in trying to take control, they were met by about 150 prisoners, who attacked them with metal tools and rubble from work that was being carried out inside the prison.

No guards were killed in the violence, but a police officer was gravely wounded with a punctured lung.

It is 4,000 inmates against 300 guards, Fasci said, adding the facility was not designed for that many prisoners or prisoners of the risk level it holds.

“It’s very difficult to keep them in order,” he said.

He said autopsies would be required to determine how many were killed by other inmates and how many by authorities. At least two appeared to have died from bullet wounds.

In March, four inmates in the same prison died after they took control of a prison pharmacy and apparently overdosed.

In another prison in Nuevo Leon, 49 prisoners died when two factions of the Zetas cartel clashed in February 2016.