A painful episode can lead to a life-long increase in an individual’s experience of pain. Fearful anticipation of imminent pain could play a role in this phenomenon, but the neurobiological underpinnings are unclear because fear can both suppress and enhance pain. Here, we show in mice that long-term associative fear memory stored in neuronal engrams in the prefrontal cortex determines whether a painful episode shapes pain experience later in life. Furthermore, under conditions of inflammatory and neuropathic pain, prefrontal fear engrams expand to encompass neurons representing nociception and tactile sensation, leading to pronounced changes in prefrontal connectivity to fear-relevant brain areas. Conversely, silencing prefrontal fear engrams reverses chronically established hyperalgesia and allodynia. These results reveal that a discrete subset of prefrontal cortex neurons can account for the debilitating comorbidity of fear and chronic pain and show that attenuating the fear memory of pain can alleviate chronic pain itself.