Opioids have been used for medicinal and recreational purposes for millennia. They constitute a broad group of pain-relieving medicines, which includes morphine, that remain effective treatments for managing pain today. Opioids attach to opioid receptors in brain cells, not only blocking pain messages but also boosting feelings of pleasure. As a result, the use of opioids for pain relief has led to growing dependence, abuse, overdose, and death. Insight into the cells and neural pathways that provide pain relief is needed to explain how morphine can have such a powerful analgesic effect as well as how they differ from neurons and pathways eliciting feelings of euphoria, well-being, and addiction. Despite decades of research, the exact neural circuit that is responsible for pain relief has remained blurred. We found that the RVM consists of multiple molecular types of γ-aminobutyric acid–mediated (GABAergic) neurons as well as a few types of glutamatergic and serotonergic neurons. Among these, morphine activated a select set of neurons, which together formed a “morphine ensemble.” Synthetic activation of the genetically captured morphine ensemble produced mechanical pain relief, mimicking the effects of morphine, and its inactivation completely abolished the effects of morphine on pain. Among the neurons in the ensemble, glutamatergic neurons projecting to the spinal cord called RVMBDNF neurons (BDNF, brain-derived neurotrophic factor) were essential. Within the spinal cord, RVMBDNF neurons were connected to GABAergic inhibitory neurons expressing the neuropeptide galanin (SCGal neurons). Inhibition of SCGal neurons completely prevented pain inhibition after administration of morphine or synthetic activation of the RVMBDNF neurons. Notably, the neurotrophic factor BDNF produced within the RVMBDNF neurons was necessary for morphine to have any effect on the sensitivity to painful stimuli. Conversely, increasing BDNF expression in the RVMBDNF neurons markedly potentiated morphine’s effects, with efficacy at doses where morphine alone was insufficient.