Morphine is an alkaloid from the opium poppy used to treat pain. The potentially lethal side effects of morphine and related opioids—which include fatal respiratory depression—are thought to be mediated by μ-opioid-receptor (μOR) signalling through the β-arrestin pathway or by actions at other receptors. Conversely, G-protein μOR signalling is thought to confer analgesia. Here we computationally dock over 3 million molecules against the μOR structure and identify new scaffolds unrelated to known opioids. Structure-based optimization yields PZM21—a potent Gi activator with exceptional selectivity for μOR and minimal β-arrestin-2 recruitment. Unlike morphine, PZM21 is more efficacious for the affective component of analgesia versus the reflexive component and is devoid of both respiratory depression and morphine-like reinforcing activity in mice at equi-analgesic doses. PZM21 thus serves as both a probe to disentangle μOR signalling and a therapeutic lead that is devoid of many of the side effects of current opioids.