MEXICO CITY — He promised to be the president of “hugs, not bullets,” and to bring peace to Mexico after years of surging criminal violence. But Andrés Manuel López Obrador is facing a public outcry after a massacre at a birthday party that has revived a sense that the country is spinning out of control.

The attack stood out for its brutality. Gunmen burst into the birthday celebration in the southern state of Veracruz on Friday night, opening fire and killing five women, seven men and a 1-year-old boy, according to the state security chief, Hugo Gutierrez.

But the shooting was just one sign of intensifying violence throughout the country. Over the weekend, the federal government released new data showing that the first quarter of the year was the most violent in recent Mexican history. A total of 8,493 people were killed, a 9.6 percent increase over the same period in 2018.

López Obrador only stoked public anger with his initial reaction to the birthday-party massacre. He called his political opponents hypocrites for criticizing him when they were “quiet as mummies” about crime-fighting failures of past administrations.

The ensuing furor has become a rare political setback for a leftist president who won a landslide victory in July by promising to fight corruption and help the poor. López Obrador has built up an 80 percent popularity rating since he took office in December.

Opposition politicians, academics and media columnists accused him in recent days of downplaying the violence and treating the criticism as a political issue.

“Isn’t this the biggest challenge that the federal government is confronting?” wrote Mauricio Merino, a political scientist from the Center for Economic Investigation and Instruction, or CIDE — a prominent think tank — in the newspaper El Universal. “What more has to happen so that we understand that the primary function of politicians is to rescue the Mexican state and not destroy it while they fight over the spoils?”

López Obrador had promised to shift Mexico’s security strategy to embrace crime prevention, arguing that many poor youths get into crime because of a lack of opportunities. He is launching major new social programs, such as scholarships for young people in poor areas.

But he has also continued policies that gave the military a central role in fighting violent crime. López Obrador has promoted the creation of a new, 80,000-member National Guard that would largely comprise former military police and national police. It will be led by a military general who has been deeply involved in the war against the cartels.

Ricardo Márquez, who formerly held senior positions in Mexico’s intelligence and security services, said the president’s plans suffered from a lack of coordination between the new security force and the plan for more social services.

He also noted that since Mexico declared an all-out offensive on drug gangs in 2006, the number of military personnel involved has increased from 37,000 to 63,000.

“This is an indication that having more military forces participating in domestic security isn’t the solution,” he said. Since 2006, organized crime groups have killed about 150,000 people, according to a U.S. Congressional Research Service report issued last year.

Gutierrez said that Friday night’s attack in the town of Minatitlan “was directed against a certain person and that person’s relatives” who were at the birthday party. He declined to give details, saying the investigation was confidential and was being handled by the state prosecutor’s office.

The news outlet Reforma quoted a person as saying the gunmen worked for the Cartel Jalisco New Generation, which has become one of the nation’s most influential crime groups in recent years. The attackers were pursuing a bar owner at the party who had not made an extortion payment, the news outlet reported.

Among those killed were bystanders, including a college student and the child, according to media reports.

In recent years, Mexican authorities have worked with the U.S. government to capture or kill many of the heads of the country’s most important drug-trafficking groups. But the organizations have splintered and diversified into other activities such as extortion, stealing gas from the state-run oil company, and car robberies.

Reacting to the outcry, López Obrador vowed Monday that his government would bring peace to Veracruz. “We inherited a serious problem of complicity between the authorities and crime groups,” he said. “We will not tolerate this.” He added that creating the new National Guard would improve the situation.

“In six months, crime levels will decrease,” he said.

Gabriela Martinez contributed to this report.

Correction: An earlier version of this report misidentified Ricardo Márquez.