The importance of having naloxone available was made clear just last week, when the United States surgeon general, Dr. Jerome M. Adams, issued a national advisory recommending that more Americans carry it and learn to use it — the first advisory from the surgeon general in more than a decade.

Naloxone comes in either an injection or a nasal spray commonly known by the brand name Narcan. New York City officials are engaged in what the city’s health commissioner calls a “full-court press” to get the drug to the public, and since last July, more than 70,000 naloxone kits have been distributed to the police, health care providers, homeless shelters and community-based organizations. When the mayor recently announced the city would spend an additional $22 million a year on anti-opioid initiatives, bringing annual funding for its HealingNYC program to $60 million, he said some of the extra funds would go toward increased training and distribution of naloxone.

But that did not mean pharmacies should be neglected, Mr. Asher said. “People might go to pharmacies who would never go into a needle exchange,” he said. If they were told they needed a prescription or had to wait for the drug, they could grow discouraged and might not have it when they needed it. The consequence?

“It’s the loss of a loved one,” he said. “Plain and simple.”

Olivia Lapeyrolerie, a spokeswoman for Mr. de Blasio, called the situation “unacceptable” and said that City Hall had instructed the health department to immediately contact all the participating pharmacies.

The drug was hardest to find outside Manhattan, The Times found. This winter, a woman in her 40s named Rebecca tried to buy naloxone in Brooklyn after learning that a friend was bingeing on prescription painkillers. (Rebecca asked to be identified only by her first name to protect her friend’s privacy.) “I’ll just throw it in my work bag and I’ll have it wherever I go,” she recalled thinking.

She pulled up the city’s map on her phone, and a number of pharmacies in Downtown Brooklyn came up. At the first Duane Reade she visited, when she asked for naloxone, “I had to repeat it a couple of times,” she said. “They were nice enough but they said they didn’t have any in stock.”