Opioids are widely used, effective analgesics to manage severe acute and chronic pain, although they have recently come under scrutiny because of epidemic levels of abuse. While these compounds act on numerous central and peripheral pain pathways, the neuroanatomical substrate for opioid analgesia is not fully understood. By means of single-cell transcriptomics and manipulation of morphine-responsive neurons, we have identified an ensemble of neurons in the rostral ventromedial medulla (RVM) that regulates mechanical nociception in mice. Among these, forced activation or silencing of excitatory RVMBDNF projection neurons mimicked or completely reversed morphine-induced mechanical antinociception, respectively, via a brain-derived neurotrophic factor (BDNF)/tropomyosin receptor kinase B (TrkB)-dependent mechanism and activation of inhibitory spinal galanin-positive neurons. Our results reveal a specific RVM-spinal circuit that scales mechanical nociception whose function confers the antinociceptive properties of morphine.