Programmed cell death ligand-1 (PD-L1) is typically produced by cancer cells and suppresses immunity through the receptor PD-1 expressed on T cells. However, the role of PD-L1 and PD-1 in regulating pain and neuronal function is unclear. Here we report that both melanoma and normal neural tissues including dorsal root ganglion (DRG) produce PD-L1 that can potently inhibit acute and chronic pain. Intraplantar injection of PD-L1 evoked analgesia in naive mice via PD-1, whereas PD-L1 neutralization or PD-1 blockade induced mechanical allodynia. Mice lacking Pd1 (Pdcd1) exhibited thermal and mechanical hypersensitivity. PD-1 activation in DRG nociceptive neurons by PD-L1 induced phosphorylation of the tyrosine phosphatase SHP-1, inhibited sodium channels and caused hyperpolarization through activation of TREK2 K+ channels. PD-L1 also potently suppressed nociceptive neuron excitability in human DRGs. Notably, blocking PD-L1 or PD-1 elicited spontaneous pain and allodynia in melanoma-bearing mice. Our findings identify a previously unrecognized role of PD-L1 as an endogenous pain inhibitor and a neuromodulator.