As lights flashed, monster beats pounded and thousands of ravers threw their arms in the air, things took a dark turn on August 31st, the second day of New York’s annual Electric Zoo festival. In separate incidents, two young fans, University of New Hampshire student Olivia Rotondo, 20, and recent Syracuse University graduate Jeffrey Russ, 23, died after apparently taking MDMA, which is commonly referred to as Ecstasy (in its pill form) and Molly (a powder). According to a New York Post report, Rotondo told an EMS worker, “I just took six hits of Molly,” before suffering a massive seizure.

Electric Zoo, which drew 90,000 dance-music fans to New York’s Randall’s Island, featured a deep lineup of top talent – including David Guetta, Avicii and Diplo. Early the next morning, organizers spoke to city officials via conference call, and all parties agreed to cancel the event’s final day – presumably, among other concerns, there was a fear that whatever had killed the young fans could still be circulating. (A toxicology report is pending; four other people were hospitalized, and there had been 31 arrests.) “Everyone said, ‘We need 100 percent assurance that we can put this on safely,'” says Stefan Friedman, spokesman for promoter Made Event, “and the decision was made that if this was not possible, we were not going to put a third day on.”

The deaths (along with that of 19-year-old Brittany Flannigan, who died the previous week after overdosing on what was presumed to be Molly at a Zedd show at Boston’s House of Blues) are tragic reminders of the complex relationship between drugs and EDM events. Since at least the early 1990s, raves and dance music have been strongly associated with MDMA. When it’s pure, the drug is significantly safer than, say, cocaine. To get a sense of how rarely MDMA is fatal, in 2011 the BBC reported that there were 500,000 yearly Ecstasy users in the U.K. and just 27 deaths.

But most fans have no way of knowing if what they are getting is real. This year, as many as 20 people in the U.K. have died after taking what they thought were Ecstasy pills, many of which contained PMA, a much more toxic drug that mimics the effects of MDMA. Molly, which has a reputation for being more pure, is at least as easy to tamper with. In fact, half of the “MDMA” recently tested at U.S. festivals by a group called DanceSafe, which makes simple testing kits available to fans online, was found to be fake. “The biggest issue with Molly is it’s a white powder, and a white powder can be absolutely anything,” says psychiatrist Julie Holland, who edited Ecstasy: The Complete Guide.

Since 2003, the Illicit Drug Anti-Proliferation Act, a law that targets dance events, has made it difficult for organizers to address this problem. Under the law, promoters can be fined $250,000, or arrested, if it can be demonstrated that they know drugs are being used at their event – severely hampering visible harm-reduction efforts. But in Portugal, for instance, where recreational use of the drug is decriminalized, things are different. “If you go to raves in Portugal, they have testing booths,” says Ed Karney, manager of top underground DJs, including Seth Troxler. “You can literally go and get all of them tested for purity every single day. In the U.K., some of the raves will have testing areas. These testing kits are readily available, and it’s just a matter of whether the authorities are going to allow that to go on.”

It’s also not clear if there really are more deaths at EDM events than at other music festivals. Ten concertgoers have died at Bonnaroo, for instance, since it began in 2002, some of them due to illegal substances. “It sucked that this happened,” says David Grutman, operating partner of Miami megaclub LIV. “We don’t promote it and it’s not allowed, but anytime there’s a party atmosphere going on, you always get those people that try to push the limits.”

Electric Zoo officials insist the festival was as safe as it could possibly be – at any given moment, 70 emergency medical technicians, 15 paramedics, five ER nurses, two physicians and numerous other medical personnel were on hand at Randall’s Island. During a press conference after the tragedy, New York Mayor Michael Bloomberg praised promoter Made Event for putting in “as good procedures as we could think of.”

But as long as young fans are gathering in huge numbers, with many of them taking drugs, there are risks. “The EDM culture exists because kids like to get fucked up and dance,” says a concert-business source. “Right now, this crowd’s doing it in electronic music. In 1969, it was called Woodstock.”