Fentanyl is a synthetic painkiller that is 30 to 50 times as powerful as heroin. It is becoming more popular among users because of its potency — it takes less than a milligram for a single use — and relatively cheap cost. Drug investigators say a worrying trend is the mixing of fentanyl with heroin or oxycodone, another popular painkiller, or counterfeit prescription pills — all sold to unwitting users.

The ease of buying opioids from China illustrates how difficult it will be for the United States to win the war on the worst drug epidemic in American history. While China has pledged to work with the United States to stop the flow of opioids, experts say it will be tough because of the country’s lax regulation of chemical companies, a sprawling industry of more than 30,000 businesses that face few requirements for transparency.

“The challenge is that when the chemical industry is so big like it is in China, policing it is incredibly difficult,” said Jeremy Douglas, the regional representative of the United Nations Office on Drugs and Crime for Southeast Asia and the Pacific.

“Regulating it — I wouldn’t say it’s impossible — but it is no small task.”

Analysts say Chinese chemical makers have exploited weak regulation to make the nation the world’s top producer of fentanyl. Mr. Trump has said fentanyl from China is “either shipped into the United States or smuggled across the southern border by drug traffickers.” The Drug Enforcement Administration said stopping the flow was a top priority.

Kai Pflug, a management consultant in the Chinese chemical industry, said that producers of fentanyl were able to avoid detection in part because they labeled their products as industrial rather than pharmaceutical, subjecting them to less stringent regulation.

“As long as, in China, you can produce chemicals without serious supervision,” Mr. Pflug said, “the problem will persist.”