The lack of satisfactory treatment for persistent pain profoundly impairs the quality of life for many patients. Stimulation of brainstem pain control systems can trigger powerful analgesia, but their complex network organization frequently prevents separation of analgesia from side effects. To overcome this long-standing challenge, we developed a biocompatible gelatin-embedded cluster of ultrathin microelectrodes that enables fine-tuned, high-definition three-dimensional stimulation in periaqueductal gray/dorsal raphe nucleus in awake rats. Analgesia was assessed from both motor reactions and intracortical signals, corresponding to pain-related signals in humans. We could select an individual-specific subset of microelectrodes in each animal that reliably provided strong pain inhibition during normal and hyperalgesia conditions, without noticeable behavioral side effects. Gait, spontaneous cortical activity at rest, and cortical tactile responses were minimally affected, indicating a highly selective action. In conclusion, our developed biocompatible microelectrode cluster and stimulation paradigm reliably enabled powerful, fine-tuned, and selective analgesia without noticeable side effects.