At one of the few chain pharmacies still open in the South Bronx — a Rite Aid on Southern Boulevard — just about everything except for the greeting cards is behind plexiglass barriers and sealed with a lock. The Kit Kats. The Pringles. The soda. The dog toys.

Yet near a subway station on that same bustling shopping street, four mom-and-pop pharmacies are doing brisk business. Their unlocked shelves are filled with merchandise. The pharmacist and technicians are on the phones, answering calls in Spanish and English from patients whose names they often know.

“I’m the kind of person who likes to speak to the patients,” said Dr. Rana Makki, supervising pharmacist at Bronx Specialty Pharmacy, a few doors down from the Rite Aid, explaining why she works there instead of a chain. “We know who you are, delivery is faster here and there you have to deal more with people stealing.”

The chain pharmacy industry nationwide is in significant turmoil. Some pharmacists are staging walkouts or quitting over poor working conditions and aggressive productivity targets. Online shopping has eaten into business. And anti-shoplifting measures, like the locked cases in the Bronx Rite Aid, are raising costs and making shopping at chain pharmacies less convenient.

Nationally, there are fears of growing pharmacy deserts, defined as areas where a lack of drugstores makes it hard to get a prescription filled.

But in New York City, where the total number of pharmacies actually grew slightly over the past year, there is a robust mom-and-pop pharmacy industry that could possibly pick up the slack. Of the 2,964 pharmacies registered with the state as of November, only about 15 percent were one of the three major chains.

The large number of local pharmacies in New York City makes it an outlier among the nation’s urban areas. According to a 2021 study, less than 1 percent of residents live in a pharmacy desert in New York City, compared with 13 percent in Los Angeles, 20 percent in Chicago and 29 percent in Houston.

As in most of the country, the number of chain pharmacies in New York City has declined significantly since the coronavirus pandemic. In 2019, there were 606 of the three major chain pharmacies — CVS, Duane Reade/Walgreens and Rite Aid — in the city’s five boroughs. By December 2023, there were 435, according to a new report by the Center for an Urban Future, a New York nonprofit that counts the number of chain stores annually.

Duane Reade/Walgreens has led the closings, shedding some 106 New York City stores since the pandemic began. But it was Rite Aid, which recently declared bankruptcy, that shrank the most this past year, closing about half of its stores across the five boroughs.

On 178th Street and Broadway in Manhattan, a sign on the door of a Rite Aid that closed last March advises customers to go to another branch seven blocks south. A Rite Aid spokeswoman said the company made “every effort to ensure our customers have access to health services,” whether at another Rite Aid or elsewhere, when a branch closes.

Nearby, two community pharmacies were humming. At Washington Heights Pharmacy and Surgical Supplies, where Goya products are sold in an aisle near the medications, Linda Pierre-Louis, a pharmacist, said that her pharmacy had picked up some patients from the Rite Aid closure, although others couldn’t transfer their prescriptions. Some unions and employers require people to get their medications through mail order, or have preferred relationships with chains.

Ms. Pierre-Louis used to work across the street at the Rite Aid, and there, theft was a huge problem. “People would come in with garbage bags; it was very disconcerting,” she said.

At her new job, she said, “a lot of our patients are local, we speak the same language.” That connection, and a much smaller store to watch, keeps theft down.

St. Jesus Pharmacy, three doors down from the old Rite Aid, was even busier, with about a dozen people working behind the pharmacy counter and a large waiting area filled with patients. Nicole Camarena, a cashier, said she believed the business was thriving because “we are more community oriented.”

Dr. Juan Tapia-Mendoza, a pediatrician and founder of a pediatric practice in West Harlem, is hoping that the decline of the chain pharmacies will further boost the independents.

At the chains, he said, pharmacists have little time to answer their phones or give patients advice. “They come and go as business decisions, not with a purpose to serve the people most vulnerable,” he said.

He counted five chain pharmacies that had left in recent years in Upper Manhattan, causing disruptions. “They invaded the neighborhood all of a sudden, and they left all of a sudden,” he said.

Representatives for the chains said they were making improvements to ensure pharmacists had more time with customers and stressed that they were a vital part of the health of communities across the country.

“Even when we make the difficult decision to close a store, it doesn’t mean we have left the community,” a Walgreens representative said, adding that there is usually another Walgreens store nearby.

But not all is rosy for the independent pharmacies. Their sector, experts warn, is fragile, with small drugstores around the country also closing as a result.

And shoplifting is still a problem for many. Drugstores in the city, including chains and independents, experienced twice as many thefts in 2022 compared with 2019, rising from 6,031 to 12,343 incidents. Since 2006, pharmacy theft has risen by more than 500 percent — more than any other category of retail, according to a recent report by researchers at John Jay College.

The Hamilton Pharmacy on Broadway and West 133rd Street was robbed six times between May and July, the pharmacist and owner, Henna Patel, said. Because she can’t afford to hire security, she now has a buzzer on the front door, so customers have to buzz in like a bank, and she closes the store now at 6 p.m. instead of 7 p.m.

“I have 32 security cameras, and people still have audacity to steal,” she said.

Still, she added, “that’s a very minor one of my problems.”

A far bigger issue, she said, is low reimbursements for the medications she sells. Across the industry, a significant percentage of the drugs that pharmacies sell do not generate enough revenue to cover costs.

“Let’s say we are buying an $3,300 H.I.V. medication; if you’re giving us $250 less, or $150 less, where are we going to recover that?” Ms. Patel asked.

At St. Jesus Pharmacy, a small sign taped to a shelf in the cold-medicine aisle hints at a cause of the problem: “Speak out against PBMs,” it says.

The sign refers to pharmacy benefit managers, little-known companies that act as middle men to negotiate prices between drug manufacturers and retailers. They also influence what medications insurance plans cover.

P.B.M.s take a percentage of the profit generated by drug sales, but do not typically disclose how much. The largest benefit managers — Express Scripts, CVS Caremark and Optum Rx — have close relationships with chain pharmacies and insurance companies. But independent pharmacies have little leverage if, for example, they get reimbursed less for a drug than a chain does.

Chris Krese, a spokesman for the National Association of Chain Drug Stores, an industry group, said that chains were also under threat from low reimbursements stemming from the role of the benefit managers. But the trade association for P.B.M.s, the Pharmaceutical Care Management Association, maintains that they protect consumers and employers from even higher prices by negotiating for discounts from drug companies.

In 2022, Gov. Kathy Hochul signed a new law aimed at regulating the benefit managing companies. However, much of the regulation promised by the legislation has yet to go into effect.

The reimbursement shortfalls mean community pharmacies are constantly trying to make ends meet in other ways. More and more, they operate like old-fashioned general stores, offering all kinds of additional products and services: passport photos, tax filing, lottery tickets, bill payment, UPS drop-off, vision testing for driver’s licenses.

At Esco Pharmacy in Hell’s Kitchen, in operation since 1940, owner Danny Dang is opening a cafe in the front of the shop to sell juices. His pharmacy is also one of only a handful in Manhattan that sells pepper spray, which requires special verification.

Because of a recent change in New York State’s Medicaid rules, he now earns a guaranteed $10 for filling each Medicaid prescription, helping him stay afloat. Still, he estimates that he’s losing money on 30 percent of his prescriptions now, compared with 60 percent before the change.

“We have to navigate and be a survivor,” he said.