Fifteen people were injured after at least one gunman opened fire and two others -- apparently security guards -- shot back before dawn inside the Blue Parrot nightclub during the BPM festival in Playa del Carmen, said Quintana Roo state attorney general Miguel Angel Pech.
Four of the victims were men, including two from Canada, one from Italy and another from Colombia, Pech said at a news conference. Organisers said three of the victims were part of the security team.
Four people were detained and authorities are investigating if they were connected to the shooting, Pech said.
State public security chief Rodolfo del Angel told Milenio television that the shooting may be linked to "a fight between people over a problem that took place inside" the club, but Pech said the investigation was ongoing.
More From This Section
The shooting sowed terror in a part of Mexico that has been largely spared from the drug violence afflicting other parts of the country.
"We suddenly had to jump over the metal security barriers because they were shooting. It was horrible. We were very scared," Eric Alvarez, a 40-year-old Mexican DJ, told AFP outside the club, which has a blue parrot painted on the facade.
Playa del Carmen is 68 kilometres south of Cancun, a Caribbean region known as the Mayan Riviera, which is very popular among American and European tourists.
An editor for London-based music magazine Mixmag who was in the backstage area of Blue Parrot said at least four or five shots were fired at around 2:45 (0745 GMT) or 3 am.
"People started running because there's an exit in the back. We stopped and hid behind a cement wall, then crawled under a metal table," Valerie Lee, Mixmag's US digital editor, was quoted as saying by the magazine.
Lee wrote on Twitter that the music was still playing five minutes after the shots were heard. The music, she said, was "super loud, likely those inside didn't even hear".