BRANDON, Miss. — A gang fight in a prison for illegal immigrants quickly escalated into a riot involving as many as 300 inmates, some lashing out with sticks or homemade knives as the uprising spread through the sprawling prison, a sheriff said.

A guard was beaten to death and at least 20 other people were injured. The riot began Sunday afternoon and lasted into the night, with inmates dragging mattresses and wood to an outdoor recreation yard to set ablaze, Adams County Sheriff Chuck Mayfield said.

While law enforcement agencies from several counties waited outside the Adams County Correctional Facility in Natchez, authorities inside responded with tear gas and tactical units. They slowly corralled the inmates into a yard and searched them. By 2:45 a.m. Monday, all prisoners were back in their cells and the prison was locked down.

Mayfield said it’s not clear if the violence began within a gang or it was a dispute between rival groups, but “once it got started, it spread like wildfire.”

“They had makeshift weapons, broom handles, mop handles, anything they could pull apart, trashcan lids for shields, anything they could grab,” Mayfield said.

The prison holds nearly 2,500 low-security inmates, with most serving time for coming back to the United States after being deported, said Emilee Beach, a prison spokeswoman. Some of the inmates have also been convicted of other crimes, but their offenses were not immediately clear.

The facility is owned by Nashville, Tenn.-based Corrections Corporation of America, one of the nation’s largest private prison companies.

Catlin Carithers, who joined CCA in 2009 and was a senior correctional officer, was beaten during the mayhem, Mayfield said.

“He liked protecting people,” Carithers’ cousin, Jason Clark, told The Associated Press.

Carithers was engaged to be married and excited about a recent promotion that took him off the weekend shifts. He had been trained in recent years as part of the prison’s special response team and was called into work Sunday to help with the uprising, Clark said.

More than two dozen officers were held hostage or were trapped at some point, the sheriff said. At least 17 prison employees were treated for various injuries and three inmates were hurt. The sheriff said the inmates hurt each other, with one getting stabbed and another had broken ribs.

Bill Chandler, executive director of the Mississippi Immigrants Rights Alliance, said his group has gotten complaints about the facility in the past year, mostly from people saying they weren’t getting adequate health care.

Frank Smith, who runs the online prison watchdog group Private Corrections Working Group, said those kinds of conditions that usually trigger a riot.

“The big problem is CCA tries to cut corners in every possible way. They short-staff, they don’t fix equipment, and things just get more and more out of control, and that’s what leads to these riots. It’s just about maximizing short-term profits,” Smith said.

The sheriff said the conditions at the prison had nothing to do with this riot, and he said there was probably little CCA could have done to stop the disturbance.

“I think this kind of thing can happen anywhere at any time,” he said.

CCA said in a statement it would work with authorities to investigate what happened.

“Unfortunately, no system is immune to disturbances,” the statement said. “Though this is only the second time in our company’s nearly 30-year history that one of our own has lost his life to inmate assault, it doesn’t make it any less tragic or difficult. This is a sad reminder of the challenges that come with providing this vital public service.”

CCA houses about 75,000 offenders and detainees in more than 60 facilities around the country, according to its website.

In 2004, inmates at a different CCA prison in Mississippi set fire to mattresses, clothing and a portable toilet. No injuries were reported. The company announced after that disturbance that it would add about 25 guards at the Tallahatchie County facility.

In Idaho, violence at a CCA-run prison has prompted federal lawsuits, public scrutiny and increased state oversight. In 2010, Vermont inmates being held at a CCA prison in Tennessee were subdued with chemical grenades after refusing to return to their cells.