From a medical textbook:
Morphine produces most of its analgesic effects by binding to the mu-opioid receptor within the central nervous system (CNS) and the peripheral nervous system (PNS). The net effect of morphine is the activation of descending inhibitory pathways of the CNS as well as inhibition of the nociceptive afferent neurons of the PNS, which leads to an overall reduction of the nociceptive transmission.
In layman’s terms it works to reduce communication between neurons, which reduces the brain’s reaction and reception of pain signals.