NEW HAVEN, Conn. — The escalating global recall of Zantac, the heartburn pill that once ranked as the world’s best-selling drug , has its roots not in government oversight or a high-profile lawsuit but in a tiny online pharmacy here whose founders feared that U.S. drugs might not be as safe as people think.

The pharmacy, Valisure, is a start-up with only 14 full-time employees. But since its scientists alerted American regulators that Zantac and its generic form, ranitidine, contained a chemical thought to cause cancer, more than 40 countries from Australia to Vietnam have either stopped sales, launched investigations or otherwise stepped in to protect consumers from possible health risks.

In the United States, the Food and Drug Administration this month confirmed unacceptable levels of the chemical, N-nitrosodimethylamine (NDMA), in some ranitidine products — including in some syrups taken by babies. FDA officials have urged people not to panic, because the levels of NDMA are similar to the amount found in grilled and smoked meats. The agency is still investigating and asking companies to recall ranitidine and a similar drug, nizatidine, if they discover unacceptable amounts of NDMA. The agency’s testing suggests Pepcid, Tagamet, Nexium, Prevacid and Prilosec do not contain the chemical.

In the meantime, major pharmacy chains have jumped ahead and yanked both brand-name and generic versions of Zantac off their shelves. Some hospitals have switched to alternatives, and major drug manufacturers have recalled products — including Sanofi, the maker of over-the-counter Zantac in the United States. The company announced a recall last month “as a precautionary measure.”

“We know impurities in medicines are of great concern to patients and consumers who rely on safe and effective medicines approved by the FDA, and we are working with manufacturers and global regulators to provide clear and actionable information,” Janet Woodcock, director of the FDA’s Center for Drug Evaluation and Research, said in a statement. “These investigations take time and do not provide instantaneous answers.”

For Valisure’s scientists, finding NDMA in ranitidine was a particularly dramatic example of the kind of discovery they make routinely. Valisure checks the chemical makeup of drugs before it ships them to consumers, and it rejects more than 10 percent of the batches because its tests detect contaminants, medicine that didn’t dissolve properly or pills that contain the wrong dose, among other issues. Since late 2018, Valisure has reported more than 50 problems directly to drug companies. Occasionally — as in the case of Zantac — their scientists find a problem so urgent they play the role of watchdog.

“I had a fairly dim view of drug quality in the United States going into this, but we’ve discovered tons of problems I never even thought of — and they’re all over the place,” said Adam ­Clark-Joseph, one of Valisure’s founders.

The FDA firmly rejects the idea that the drug supply is unsafe and said that one of Valisure’s conclusions — that ranitidine turns into NDMA in the stomach — is not supported by the agency’s testing. The agency reviews reams of data before approving a drug, inspects factories that make them, runs its own tests on selected drugs and collects reports of safety problems.

“Americans can be confident in the quality of the products the FDA approves,” spokesman Jeremy Kahn said.

Valisure makes money the same way other pharmacies do — buying drugs from wholesalers and taking a cut of the price when it sells them. To set itself apart, it chemically tests the medicines it dispenses — marketing its services on the premise that people can’t be confident about what’s inside the pill bottles that fill their bathroom cabinets.

Clark-Joseph, an economist with some chemistry training, was drawn to the idea because he kept getting sick. In graduate school, he refilled a prescription only to find that the new, supposedly identical drug didn’t work. When his doctor told him to try another pharmacy because he probably got a bad batch, he was appalled. After similar incidents occurred, he started searching for a lab that would verify the chemical contents of his medication. When he didn’t find an obvious solution, he called his college friend David Light, who had worked in biotech, and suggested that they partner on a business that would verify the chemical contents of drugs.

“He thought I was being kind of paranoid at first,” Clark-Joseph said.

Light researched the issue and became convinced that it was a real problem — and a potential opportunity. But it wasn’t easy to sell investors on the concept, so the two friends provided much of the initial funding for the company from their own bank accounts.

In a modest two-room laboratory in a former gun factory, Valisure’s half-dozen scientists churn pills in a solution formulated to mimic stomach acid and warmed to body temperature, a test to determine whether medicines dissolve properly. They use lasers to probe pills for inactive ingredients. A specialized instrument used in forensic investigations is used to detect carcinogens. Each time the company has expanded its panel of tests, new problems with medications have emerged.

One of the first drugs it tested was lamotrigine, an anticonvulsant medication made by several generic drug companies. (Valisure typically doesn’t disclose the makers of a specific batch that failed its quality standards.) Valisure’s scientists put different batches of the extended-release version of the pill into a fancy blender that emulated the stomach and were dismayed at the results. Multiple batches took longer than 24 hours to dissolve, and one took more than 48 hours — despite the fact that the label said it was supposed to dissolve in 12 to 15 hours. Ultimately, they found a version that met their standard to dispense to patients. Decals depicting the chemical structure of lamotrigine now decorate a wall of the pharmacy.

Late last year, the company published a scientific paper showing that rapid-release Tylenol dissolved more slowly than less expensive tablets of the same dose. This wasn’t a public health problem, but it made the marketing of one of the most familiar drugs seem misleading.

Ernie Knewitz, a spokesman for Johnson & Johnson, the maker of brand-name Tylenol, said at the time the gelcaps were “rapid release” in comparison with conventional gelcaps, not uncoated tablets. The company did not respond to a request for an update.

After Valisure added a carcinogen test in March, it threw a form of ranitidine, the active ingredient in Zantac, into the queue — because Clark-Joseph’s infant daughter was taking the drug for acid reflux. Kaury Kucera, the chief scientific officer, recalled seeing with disbelief a spiking peak on a graph that indicated the presence of a large amount of NDMA. She ran the test again. Then she ran into Light’s office. He called Clark-Joseph and warned him to hold off on giving his daughter the drug until they could sort out what this meant. Scientists worked feverishly to confirm and understand the result. They sent samples to an independent lab to verify their finding. In June, they alerted the FDA to their initial results.

Much of the concern over the quality and safety of the drug supply has been propelled by a massive movement of drug production to foreign factories in recent years, “driven by the pharmaceutical industry’s desire for cost savings and less stringent environmental regulations,” Woodcock said in testimony submitted to Congress in October.

The FDA rigorously evaluates drugs for effectiveness and safety before approval, including visits by inspectors, who review records to ensure compliance with requirements — including that companies test batches of medicine before distributing them, Kahn said.

A 2016 Government Accountability Office report found that almost a third of 3,000 foreign drug establishments licensed by the FDA may not have been inspected, although the FDA said it has now caught up on the backlog.

Sen. Charles E. Grassley ­(R-Iowa), has sent letters to the FDA questioning the adequacy of its foreign drug inspection program.

David Gortler, a former FDA official who now works as chief medical officer of Valisure, says that inspections simply aren’t sufficient in foreign factories. He thinks the agency needs to test each batch of drug that enters the country.

Companies have been cited by the FDA not just for technical mishaps and errors but occasionally also for systematic failures to properly investigate quality problems.

“It’s really becoming a national health crisis,” Gortler said, “and eventually it’s going to become a national security crisis.”

Kahn, the FDA spokesman, said the agency “regularly samples and tests selected drug products.” A survey of 323 products in 2015 found that all drugs met the agency’s standard for potency and purity, he said.

But the FDA’s own data shows that testing is selective. At the end of 2013, there were 12,100 approved drugs. Over the previous decade, the agency had tested fewer than 4,000 of them.

Valisure sees that gap as an opportunity. The company first alerted U.S. regulators in June that Zantac and ranitidine products contained a probable carcinogen. In September, Valisure filed a citizens petition to have the products pulled from the market entirely, and the FDA issued an alert to the public that the agency had learned some products contained NDMA. Follow-up testing had led Valisure’s scientists to suspect that the drug wasn’t contaminated but that the drug itself is unstable and could form NDMA, particularly in the conditions found in the stomach.

Woodcock testified before Congress that FDA scientists do think the drug might be reacting with itself to form NDMA. But the FDA said the levels of NDMA it has found are lower than Valisure flagged and that it is not formed in the stomach. “We still must test the drugs in the human body to fully understand if ranitidine forms NDMA,” Woodcock said in a statement.

GlaxoSmithKline, the company that first brought Zantac to market in the 1980s, said in a statement that its scientists had carefully examined whether the drug could form NDMA in the stomach when Zantac was being approved.

“The reason for the current precautionary recall of ranitidine is due to an emerging finding that some sources of drug substance and therefore drug product may contain very small amounts of nitrosamine,” the statement said.

Sanofi critiqued Valisure’s testing, saying the high levels of the chemical formed “only after exposing ranitidine to extreme artificial conditions.”

Sanofi said on Oct. 18 that it would recall its over-the-counter Zantac in the United States and Canada, noting “inconsistencies” in its preliminary test results of the active ingredient in drugs sold in both countries, which were sourced from different suppliers. Several other major ranitidine manufacturers have also pulled their U.S. products, including Novartis’s Sandoz division, Dr. Reddy’s Laboratories and Apotex.

Sandoz and Dr. Reddy’s both cited “confirmed contamination” above the FDA’s limits in a statement. Apotex said its recall was on a “precautionary basis.”

Meanwhile, GSK has recalled its products overseas and is investigating the possible source of the NDMA. (GSK no longer sells ranitidine products in the United States.)

Exposure to low levels of NDMA, which occurs naturally in food and the environment, is not acutely dangerous. But if consumers wonder what to make of the growing recalls, they are not alone.

Erin Fox, senior director of Drug Information and Support Services for University of Utah Health, purchases medicines for a hospital system with 5,000 drugs on the formulary. Not a day goes by without a recall notice of some kind, she said — adding that as soon as Valisure’s petition became public, her hospital swapped ranitidine products for an alternative.

Fox is a drug safety nerd. She geeks out on reading the warning letters and inspection documents the FDA posts about drug factories. Fox then tries to sleuth out more information, calling up company contacts.

“I’m almost always completely frustrated and thwarted,” Fox said. “We have a pass-fail system in the U.S., where it’s on the market or not on the market, and FDA does not provide us with any kind of quality metrics. In many cases, we don’t even know the company that is making the product.”

That can make it difficult to understand whether, when a problem is detected, it is a single bad batch or an example of a much broader problem. Over the past year and a half, an expanding recall of blood pressure medicines have been traced back to a problem in the manufacturing process in factories in China and India, according to the FDA.

Consumers may not care where their drugs are made, as long as they are safe and effective, and that’s what the FDA monitors through programs that tally adverse effects. But that system is imperfect. Many side effects — or people’s perception that a pill doesn’t work very well — may never be reported.

And for chemicals such as NDMA, which may be harmful over the long term, there may be no immediate health impact to report.

William Mitch, an environmental engineering professor at Stanford University, generated support for the idea ranitidine could turn into NDMA in the stomach several years ago, while investigating the presence of NDMA in wastewater. As a side study, he asked 10 volunteers to collect urine samples before and after ingesting a Zantac.

Mitch found high levels of NDMA in their urine after they ingested the pill, in some cases more than 45,000 nanograms. The FDA has set the acceptable daily intake of NDMA at 96 nanograms.

“That was concerning, but we don’t know that field,” Mitch said. “We sort of did it to spur further interest.”

GSK cited studies from the late 1980s and early 1990s that did not find a substantial increase in NDMA levels in people taking Zantac.

“Extensive pharmacovigilance monitoring, regular safety reviews and substantive epidemiological studies have not linked ranitidine to raised cancer risks,” GSK said in a statement.

The disagreement over the source of NDMA adds urgency to the investigation by regulators and companies. For Valisure, identifying problems can be a form of marketing, and the global attention over Zantac has helped boost business. But increasingly, its employees see themselves as patient advocates.

“We always thought of consumer protection . . . as an important part of what we would do, but I never appreciated how big of a problem we’re watching over,” Light said. “We find more problems than we have resources to fully investigate.”