A gunman opened fire at a nightclub in the popular Mexican resort of Playa Del Carmen early Monday – killing five people and sparking a stampede on the last day of an electronic music festival, officials said.

An 18-year-old woman from Denver, Alejandra Villanueva Ibarra, was among the dead, according to the US Embassy in Mexico.

The other victims were all men: one Canadian, an Italian and two Mexicans.

Three of those killed were part of the security detail at the event, said Miguel Angel Pech, the attorney general of Quintana Roo state. The fourth and fifth victims, including a fleeing woman, were not immediately identified.

Fifteen people were injured – including two US citizens — some in the rush to escape from the bustling nightspot, where the attacker had apparently been denied entry because he had a gun, Pech said.

The gunman then began to exchange fire with another person inside. The three security guards came under attack when they responded to the shooting, which Pech said was not related to terrorism.

He said 20 bullet casings from three pistols were found at the scene, but it was unclear if the guards had been armed or fired any of the weapons.

Three people were detained nearby, but it was unclear if they had been involved in the incident.

“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 who lost his prosthetic teeth while fleeing, told Agence France-Presse.

An editor for the London-based music magazine Mixmag was in the backstage area of the club when shots rang out.

“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, told AFP.

“Security guards at first didn’t think it was shots and kept claiming it was fireworks, saying everything was OK. Then people kept running and said they saw a gun. We kept hiding until they opened the back gate and we ran outside,” Lee said.

Lee tweeted that the music was still playing five minutes after the shots were heard. The music, she wrote, was “super loud, likely those inside didn’t even hear.”

Sonny Shilcock, 20, from Essex, UK, was with four pals when the shooting erupted.

“I was at the front of the club but heard about five very loud bangs and thought it was part of the DJ’s set until panic spread through the crowd,” he told The Sun of the UK.

“We’d carried on dancing until a wave of fear went through the place and everyone hit the deck,” he said. “I was one of the last to get out and saw one man who was clearly dead covered in a lot of blood.”

George de Menezes told The Independent of the UK that bullets whizzed by just feet from him.

“No one took it seriously, but I knew straight away that it was a gun and dropped to the floor, then everyone dropped with me,” he said. “The music stopped and so did the shots, so we got up and one man was down on the floor and looked dead, and another man had been shot but was trying to stay on his feet.

“Everyone tried to run out to the beach from the club and all of a sudden we heard another shot and everyone dropped again and it kept going on,” he said.

The state of Quintana Roo expressed its sorrow over the violence, which dealt a blow to Mexico’s tourism industry.

“We stand in solidarity with the families of the victims and all those who have been affected by this tragic event,” the state’s Ministry of Tourism said.

“Those who were injured are receiving medical attention in the area’s health centers and family members have been offered any necessary assistance. Government authorities from the local, state and federal level, are in the process of an exhaustive investigation to assure that those responsible of this deplorable act will be punished to the full extent of the law.”

With Post wires