Pain is fundamentally unpleasant and induces a negative affective state. The affective component of pain is mediated by circuits that are distinct from those mediating the sensory-discriminative component. Here, we have investigated the role of prostaglandins in the affective dimension of pain using a rodent pain assay based on conditioned place aversion to formalin injection, an inflammatory noxious stimulus. We found that place aversion induced by inflammatory pain depends on prostaglandin E2 that is synthesized by cyclooxygenase 2 in neural cells. Further, mice lacking the prostaglandin E2 receptor EP3 selectively on serotonergic cells or selectively in the area of the dorsal raphe nucleus failed to form an aversion to formalin-induced pain, as did mice lacking the serotonin transporter. Chemogenetic manipulations revealed that EP3 receptor activation elicited conditioned place aversion to pain via inhibition of serotonergic neurons. In contrast to their role in inflammatory pain aversion, EP3 receptors on serotonergic cells were dispensable for acute nociceptive behaviors and for aversion induced by thermal pain or a κ opioid receptor agonist. Collectively, our findings show that prostaglandin-mediated modulation of serotonergic transmission controls the affective component of inflammatory pain.