Scientists have figured out how to brew morphine using the same kit used to make beer at home.
They have genetically modified yeast to perform the complicated chemistry needed to convert sugar to morphine.
The findings, published in Nature Chemical Biology, raise promise for medicine but also concerns about "home-brewed" illegal drugs.
Experts have called for tight control of organisms genetically modified to produce narcotics.
If you brew beer at home, then you are relying on microscopic yeast that turns sugars into alcohol.
But by borrowing DNA from plants, scientists have been genetically engineering yeasts that can perform each of the steps needed to convert sugar into morphine.
One stage of the process - the production of an intermediary chemical called reticuline - had been a stumbling block.
That has been solved by a team at the University of California, Berkeley, and the scientists say it should now be possible to put all the steps together and "brew" morphine.
Dr John Dueber, a bioengineer at the university, said: "What you really want to do from a fermentation perspective is to be able to feed the yeast glucose, which is a cheap sugar source, and have the yeast do all the chemical steps required downstream to make your target therapeutic drug.
"With our study, all the steps have been described, and it's now a matter of linking them together and scaling up the process.
"It's not a trivial challenge, but it's doable."
Morphine plays a vital role in pain relief in many hospitals, but it requires a poppy harvest to manufacture.
Brewed morphine could, eventually, be easier to produce. It could also allow scientists to tweak each of the steps to develop new types of painkiller.
The broad concept of using microscopic organisms to make drugs is not new in medicine.
Insulin for people with diabetes has been made in genetically modified bacteria for decades.
But there are concerns these latest advances could allow a DIY drug lord to brew illegal narcotics in their home.
"In principle, anyone with access to the yeast strain and basic skills in fermentation would be able to grow morphine producing yeast using a a home-brew kit for beer-making," reads a comment piece in Nature journal.
It calls for tight controls on such genetically modified yeasts.
Prof Paul Freemont, one of the directors of the Centre for Synthetic Biology and Innovation at Imperial College London, said: "Making opioids that can be used in an illegal sense makes this an important story.
"It's technically demanding to make these strains, but in the future who is to know?
"That is why this is such an important time - how do we regulate these strains?"