MEXICO CITY — At least 27 people were killed in an attack in the Mexican state of Veracruz when assailants apparently locked the doors and emergency exits of the popular White Horse Nightclub and then set the building on fire.

The attack late Tuesday came during a year of record violence for Mexico, which registered 14,603 homicides from January through June. The Mexican government under President Andrés Manuel López Obrador has struggled to piece together an effective security strategy as criminal organizations claim new ground, killing members of rival groups and civilians in the process.

López Obrador condemned the attack on Wednesday — and then suggested authorities might have been complicit.

“This is the most inhuman thing possible,” López Obrador said. “It is regrettable that organized crime acts in this manner. …

“It is more regrettable that there may be collusion with authorities.”

Photos of the bar taken in the aftermath of the attack show a charred interior with bodies on the ground. People were seen embracing outside the bar, behind police tape.

Some early reports indicated the fire had been started with homemade bombs. López Obrador, in his morning news conference, said “the criminals went in, closed the doors, the emergency exits, and set fire to the place."

“The majority died of suffocation,” Veracruz Gov. Cuitláhuac García told the “Sergio y Lupita” radio program Wednesday morning.

The bar is in the port city of Coatzacoalcos, which has been plagued by violence, caused in part by fractures within the Zetas criminal organization. Last week, a 4-month-old child was critically wounded in a shootout.

In recent years, Mexico has faced the dual challenges of trying to build a large, effective security force capable of cracking down on crime and also a judicial system that can hold the guilty accountable. On both fronts it has struggled, with Veracruz a jarring example. The state police force is 61 percent smaller than it should be, López Obrador said this month.

The state was supposed to receive 7,200 members of the newly formed national guard, drawn from a mix of different federal and state security agencies. But many of those officers have been dispatched on an immigration enforcement mission, part of the U.S.-Mexico deal to reduce the number of migrants arriving at the U.S. border. López Obrador, who created the national guard, once spoke of it as a potential vanguard in the fight against organized crime.

Other parts of Mexico have also seen dramatic violence in recent weeks. Cartels were blamed for a gruesome attack this month in the western city of Uruapan, where 19 mutilated corpses were left on display. A Catholic priest, the Rev. José Martín Guzmán Vega, was stabbed to death last week in the northern city of Matamoros. Across the country, four journalists have been killed in the past month alone.

“The fact that 2019 is on pace to be the most violent year does not come out of nowhere. We have seen how violence has been progressively increasing,” said Francisco Rivas, director general of the National Citizen Observatory, a research group. The increase, he said, is the result of an “incapacity of the state, lack of identification of the problem, with no clear goals or strategies.”

“The president says we are improving, but we are worse than ever before."

Within hours of Tuesday’s attack, López Obrador suggested the perpetrator had previously been “arrested and released.”

“There is a problem that needs to be investigated regarding the actions of the prosecutor’s office in Veracruz, and we are telling the attorney general to look into this matter,” he said.

López Obrador did not mention anyone by name, but he appeared to be referring to a statement from García, the Veracruz governor, who tweeted about the man he suggested was behind the attack.

“The indications of the deplorable crime in the Coatzacoalcos bar suggest that one of the material authors is Ricardo 'N' a.k.a. 'la loca’ who was detained by Veracruz security forces in July of this year and was released in less than 48 hours by the state attorney general,” García wrote.

The state attorney general promptly put out a statement contradicting García’s account.

“A tragedy should not be used to distort facts and confuse public opinion,” Veracruz Attorney General Jorge Winckler Ortíz said.

He went on to say that Ricardo N. was twice detained and released by the federal government — on July 18 and Aug. 7 — not the state attorney general’s office. The dispute shed light on fractures within Mexico’s judicial system, with blame shifting between state and federal authorities.

Veracruz authorities said they were still searching for the attackers.

The deadly attack came nearly eight years to the day after the Zetas drug cartel started a fire at a casino in the northern city of Monterrey, killing 52 people.

Mary Beth Sheridan and Gabriela Martinez contributed to this report.