Mu-opioid receptors (MORs) are crucial for analgesia by both exogenous and endogenous opioids. However, the distinct mechanisms underlying these two types of opioid analgesia remain largely unknown. Here, we demonstrate that analgesic effects of exogenous and endogenous opioids on inflammatory pain are mediated by MORs expressed in distinct subpopulations of neurons in mice. We found that the exogenous opioid-induced analgesia of inflammatory pain is mediated by MORs in Vglut2+ glutamatergic but not GABAergic neurons. In contrast, analgesia by endogenous opioids is mediated by MORs in GABAergic rather than Vglut2+ glutamatergic neurons. Furthermore, MORs expressed at the spinal level is mainly involved in the analgesic effect of morphine in acute pain, but not in endogenous opioid analgesia during chronic inflammatory pain. Thus, our study revealed distinct mechanisms underlying analgesia by exogenous and endogenous opioids, and laid the foundation for further dissecting the circuit mechanism underlying opioid analgesia.