Opium is a narcotic formed from the latex (i.e., sap) released by lacerating (or "scoring") the immature seed pods of opium poppies (Papaver somniferum). It contains up to 10% morphine, an opiate alkaloid, which is most frequently processed chemically to produce heroin for the illegal drug trade. The resin also includes codeine and non-narcotic alkaloids, such as papaverine and noscapine. Meconium historically referred to related, weaker preparations made from other parts of the poppy or different species of poppies. Modern opium production is the culmination of millennia of production, in which the source poppy, methods of extraction and processing, and methods of consumption have become increasingly potent.

Cultivation of opium poppies for food, anesthesia, and ritual purposes dates back to at least the Neolithic Age. The Sumerian, Assyrian, Egyptian, Minoan, Greek, Roman, Persian and Arab Empires each made widespread use of opium, which was the most potent form of pain relief then available, allowing ancient surgeons to perform prolonged surgical procedures. Opium is mentioned in the most important medical texts of the ancient world, including the Ebers Papyrus and the writings of Dioscorides, Galen, and Avicenna. Widespread medical use of unprocessed opium continued through the American Civil War before giving way to morphine and its successors, which could be injected at a precisely controlled dosage. American morphine is still produced primarily from poppies grown and processed in India in the traditional manner and remains the standard of pain relief for casualties of war.

Recreational use of the drug began in China in the fifteenth century but was limited by its rarity and expense. Opium trade became more regular by the seventeenth century, when it was mixed with tobacco for smoking, and addiction was first recognized. Opium prohibition in China began in 1729 and was followed by nearly two centuries of exponentially increasing opium use. China had a positive balance sheet in trading with the British, which led to a decrease of the British silver stocks. Therefore, the British tried to encourage Chinese opium use to enhance their balance, and they delivered it from Indian provinces under British control. A massive confiscation of opium by the Chinese emperor, who tried to stop the opium deliveries, led to two Opium Wars in 1840 and 1858, in which Britain suppressed China and traded opium all over the country. After 1860, opium use continued to increase with widespread domestic production in China, until more than a quarter of the male population was addicted by 1905. Recreational or addictive opium use in other nations remained rare into the late nineteenth century, recorded by an ambivalent literature that sometimes praised the drug.

Global regulation of opium began with the stigmatization of Chinese immigrants and opium dens, leading rapidly from town ordinances in the 1870s to the formation of the International Opium Commission in 1909. During this period, the portrayal of opium in literature became squalid and violent, British opium trade was largely supplanted by domestic Chinese production, purified morphine and heroin became widely available for injection, and patent medicines containing opiates reached a peak of popularity. Opium was prohibited in many countries during the early twentieth century, leading to the modern pattern of opium production as a precursor for illegal recreational drugs or tightly regulated legal prescription drugs. Illicit opium production, now dominated by Afghanistan, has increased steadily in recent years to over 6600 tons yearly, nearly one-fifth the level of production in 1906. Opium for illegal use is often converted into heroin, which multiplies its potency to approximately twice that of morphine, can be taken by intravenous injection, and is easier to smuggle.