On a Thursday night last October, Ryan Carlos set off the metal detectors at the door of Brooklyn Steel, a popular music venue in Williamsburg. A security guard pulled him aside, patted him down and instructed him to turn out his pockets.

He pulled out a box containing Narcan — a nasal spray version of the drug, naloxone — which can reverse overdoses brought on by opioids like fentanyl in a matter of seconds.

“He abruptly cut me off and said, ‘I know what it is. You need to throw it away or you can’t come in the venue,’” Mr. Carlos said in an interview.

On social media and online message boards, other partygoers have posted about similar encounters — including aggressive questioning by security guards — at other venues, including Warsaw and Basement, and at the Twilight Harbor festival held at the Brooklyn Navy Yard in October.

The venues have blamed overzealous and poorly trained guards. But the incidents are at odds with a city initiative known as “NARCAN Behind Every Bar,” which was launched last year to supply the lifesaving antidote to clubs, bars and venues across the city.

“Everyone should be carrying naloxone,” said Dr. Ashwin Vasan, commissioner of the New York City Department of Health and Mental Hygiene. “It definitely shouldn’t be taken away from you.”

The incidents highlight the challenges the city faces in tackling a disturbing trend: A New Yorker dies of a drug overdose every three hours, according to the Department of Health. More than 3,000 people died in drug overdoses in the city in 2022. Officials expect 2023 to be worse.

But these efforts have been fraught: A federal prosecutor recently questioned the legality of the safe injection sites. And law enforcement officials face a difficult balance as they try to halt the distribution of drugs in the city without criminalizing users.

Fentanyl — which is 30 to 50 times more potent than heroin — has been detected in 81 percent of the more than 3,000 drug overdose deaths in the city last year, according to the Department of Health. But because the opioid is often mixed with other drugs, like cocaine, it can be difficult to spot, meaning many people who buy drugs on the street end up using it unknowingly.

Because more than 7 percent of the 2022 deaths occurred in “public indoor” spaces, which include bars and clubs, the city has turned to those places for help. For the most part, said Dr. Vasan, “nightlife has been a great partner,” and he believes that cases like Mr. Carlos’s are isolated.

Many bar and club owners said they were happy to help. Some bars also offer fentanyl testing strips to customers.

Dennis Dennehy, a spokesman for Bowery Presents, which operates Brooklyn Steel, became aware of the incident after seeing Mr. Carlos’s post on the media platform X.

“Bowery Presents allows Narcan to be brought into all venues, and we also keep it on-site,” he said.

In an email, Tyler Myers, the co-founder and executive director of Knockdown Center, which operates Basement, said, “We do not, and have not, ever confiscated Narcan.” The statement said the venue keeps Narcan throughout the facility and has held trainings for staff. Operators at Warsaw and the Twilight Harbor festival did not respond to emailed requests for comment.

Other venue owners speculated that a lack of awareness may be behind decisions to confiscate Narcan.

“If security is taking it away from customers, it’s probably because they’re misinformed,” said Jon Corbett, who owns Eris, a venue in Brooklyn that stocks Narcan on-site.

To become a registered security guard, one is required to undergo hours of training run by the New York State Division of Criminal Justice Services. But Janine Kava, a spokeswoman for the agency, confirmed that it did not require opioid overdose prevention training as part of the two courses that people need to take to obtain a license, although it was offered as an optional “refresher training.”

John Barclay, the owner of the popular dance clubs Paragon and Bossa Nova Civic Club, thinks guards may also be assuming that people who carry Narcan plan to use illicit drugs.

“Probably half of the people that keep it on their person do not engage in drug use at all,” he said. “They’re just good Samaritans.”

Brooklyn Steel’s owners noted that security was handled by an outside company, 5280 Group, which also operates at six other New York venues.

In a statement, the company said the guard who confronted Mr. Carlos had been hired recently and was “overzealous,” adding that “the incident was a teachable moment.” Since that night, the company said it had made reminders about its Narcan policies a part of the nightly meeting that security employees attend before each shift begins.