The dramatic shooting attack sent tourists scrambling for cover at the resort of Puerto Morelos, just south of Cancun.
The two suspected drug dealers killed Thursday had apparently arrived at the beach in front of the Azul Beach Resort and the Hyatt Ziva Riviera Cancun earlier in the day, claiming it was now their territory.
"About 15 people arrived on the beach to assassinate two men who had showed up saying they were the new dealers in the area," the head prosecutor of Quintana Roo state, Oscar Montes de Oca, told the Radio Formula station.
Montes de Oca's office said earlier in a statement that "there was a clash between rival groups of drug dealers on a beach" near the hotels. Several cartels are fighting for the area's lucrative retail drug trade, including the Jalisco cartel and the a gang allied with the Gulf cartel.
Montes de Oca said one of the men targeted in the attack fled into one of the hotels before dying. The other was killed on the beach. He also said one person suffered non-life-threatening injuries in the attack, but authorities could not determine whether that person was a hotel employee or a guest because they were still undergoing medical treatment.
WATCH: Cancun hotel guests shelter in place amid reports of active shooter
Gov. Carlos Joaquin said the commando wore ski masks and arrived by boat at the beach. Montes de Oca said they fled in a boat after the attack.
Joaquin called the attack "a serious blow to the development and security of the state ... putting the image of the state at grave risk."
The shootings were the latest chapter in drug gang violence that has sullied the reputation of Mexico's Caribbean coast as a once-tranquil oasis.
Guests at the Hyatt Ziva Riviera Cancun posted videos and photos of tourists hiding or nervously milling in the lobby and hallways of hotels during the incident.
Guests at the nearby Azul Beach Resort also posted videos of people taking shelter or gathering in the lobby. An employee who answered the phone at the hotel said the shooting occurred on the beach near the facility.
Mike Sington, a guest at the Hyatt Ziva Riviera Cancun, wrote in his Twitter account that "Guests are telling me they were playing volleyball on the beach, gunman approached firing gun. Everyone ran from beach and swimming pools. Staff hustled us into hidden rooms behind the kitchens."
Sington tweeted "I've never been so scared, literally shaking," before adding "I'm fine now, barricaded in my hotel room for the night, just trying to decompress."
Rival cartels often kill another gang's street-level dealers in Mexico to eliminate competition and ensure their drugs are sold first. It is not the first time that tourists have been caught in the crossfire of such battles.
The Puerto Morelos shooting comes two weeks after a California travel blogger and a German tourist were killed in a similar shootout in the beach town of Tulum.
A San Jose, California woman born in India, Anjali Ryot, and German citizen Jennifer Henzold were apparently hit by crossfire from the Oct. 20 drug dealers' shootout in Tulum, south of Puerto Morelos.
Three other foreign tourists were wounded in the shooting at a street-side eatery that has some outdoor tables, right off Tulum's main strip. They included two German men and a Dutch woman.
The German Foreign Office issued a travel advisory about the violence, advising its citizens "if you are currently in the Tulum or Playa del Carmen area, do not leave your secured hotel facilities."
The Tulum gunfight also apparently broke out between two groups that operate street-level drug sales in the area, according to prosecutors.
Montes de Oca said eight suspects in the Tulum attack had been detained in possession of firearms.
There have been signs that the situation in Quintana Roo state, where all the resorts are located, was out of control months ago. In June, two men were shot to death on the beach in Tulum and a third was wounded.
And in nearby Playa del Carmen, police stage a massive raid in October on the beach town's restaurant-lined Quinta Avenida, detaining 26 suspects - most apparently for drug sales - after a city policewoman was shot to death and locked in the trunk of a car last week. Prosecutors said Friday they have arrested a suspect in that killing.
Crime "has gone up a little with extortion, with drug sales to foreigners and Mexicans," the prosecutors office said about the raid.
The administration of President Andrés Manuel López Obrador has pinned its hopes on the so-called Maya Riviera, where it has announced plans to build an international airport and a stop for the Maya train, which will run in a loop around the Yucatan peninsula.