This article has been revised to remove a quotation that prompted threats by telephone and social media.

MEXICO CITY — The beachside dance floor was packed. The pulse of electronic music throbbed. In the middle of the pandemic, in the crowd of maskless dancers, some tourists commented to each other: "Tulum is back."

“It felt like covid was over. The borders are open. The world is back to normal. Let’s just have fun,” said Alexandra Karpova, 31, a public relations executive who flew from New York to attend the November festival, called Art With Me, on Mexico’s Riviera Maya on the Caribbean coast.

But in the days after the festival, dozens of attendees tested positive for the coronavirus. Some brought it back to the United States.

The incident prompted a question at the heart of Mexico’s economic recovery: Is the country — with among the highest coronavirus caseloads in the world — taking too many risks to re-energize its lucrative tourism sector?

Remarkably, the number of American tourists visiting the state of Quintana Roo, where Tulum and Cancun are located, has increased by 23 percent compared with 2019. With Europe closed to most Americans, Mexico has successfully marketed itself as a desirable alternative. Roughly 100 flights from the United States are now landing in Quintana Roo every day.

Many tourists are coming to stay at coastal resorts, where masks are mandatory in public places. Others are going on scuba diving tours or taking kite surfing lessons. But Tulum’s global reputation as a party destination has not changed during the pandemic.

“There are parties almost every night,” said Maria Prusakova, 30, the founder of a public relations firm, who traveled to Tulum in July from San Francisco.

When the restaurants closed at 11 p.m., she said, the parties started at private villas. No one wore masks. Prusakova got sick at the same time as 12 of her friends. They all tested positive — in her case, only after she returned to San Francisco.

Prusakova is returning to Tulum for New Year’s Eve, when the city is typically packed with parties. This year, authorities say they won’t permit them. State officials say they are scanning social media to find any mention of large gatherings. Event organizers are quietly telling tourists that they will find a way to host parties.

“We need to find a way to create jobs. Otherwise, the situation will continue getting worse,” said Marisol Vanegas, the state secretary of tourism. “But we always prioritize public health.”

In the first few months of the pandemic, Quintana Roo lost more than 100,000 jobs in the tourism sector, which makes up more than 80 percent of the state’s revenue. In Tulum, the unemployment rate hit 50 percent in May, according to the mayor’s office. Across Mexico, tourism generates about 17 percent of the country’s gross domestic product.

Officials pledged to get that revenue back by attracting more Americans. Quintana Roo formally declared tourism an “essential” service.

For months, wealthy Americans held private parties in villas and hotels along the coast. When Art With Me was held in November, the government of Tulum granted permission to event organizers to host more than 1,200 guests, with each party or event capped at 300 people.

“It felt like Burning Man on the beach,” Karpova said. “There was just an amazing energy. People were just so thirsty to be together. It was like, ‘We’re free again.’ ”

In the days after the festival, the Hospital de Tulum saw a surge in testing requests, almost all from foreign tourists. Nearly all of those tests came back positive.

“A big part of this tourism is young people, used to partying, used to dancing. Many of them, when they get sick, are asymptomatic, but they’ve interacted with locals who might not be,” said Marco Rodriguez, the hospital’s administrative director. “People come here because they want to go to the biggest and best parties in Mexico, but the people hosting these events need to comply with the law.”

Officials in Tulum and Quintana Roo have played down the impact of tourism on the spread of the pandemic. Nearly 2,000 people have died in the state, according to official statistics. Experts say the number is probably much higher.

“We’ve prioritized sanitary measures and health, and the level of the contagion in Tulum has remained low,” said the city’s mayor, Victor Mas.

Mas said that Art With Me had “moments of irresponsibility, but it’s not a generalized problem.”

Last month, the U.S. Centers for Disease Control and Prevention warned Americans against traveling to Mexico, saying in a statement that there is a “very high level of Covid-19” in the country. But Americans have continued to make the trip. Infamously, Austin Mayor Steve Adler issued a video message last month urging people “to stay home if you can.” It turned out he had recorded the message from Cabo.

After people learned of the surge in cases related to Art With Me, they started posting angry comments on the festival’s Facebook page.

“Tulum once again shows us it is about greed and this time this greed is going to kill others,” wrote one person.

“New Yorkers did not need you going to and returning from a superspreader event,” wrote another.

The debate about balancing tourism revenue and prioritizing public health has flared in other parts of Mexico, too. In Acapulco, the city launched a marketing campaign in the middle of the pandemic, which included a voice-over saying “there are no rules” and boasted about late-night parties.

The advertisement was quickly withdrawn.