Chronic visceral pain can occur in many disorders, the most common of which is irritable bowel syndrome (IBS). Moreover, depression is a frequent comorbidity of chronic visceral pain. The P2X7 receptor is crucial in inflammatory processes and is closely connected to developing pain and depression. Gallic acid, a phenolic acid that can be extracted from traditional Chinese medicine, has been demonstrated to be anti-inflammatory and anti-depressive. In this study, we investigated whether gallic acid could alleviate comorbid visceral pain and depression by reducing the expression of the P2X7 receptor. To this end, the pain thresholds of rats with comorbid visceral pain and depression were gauged using the abdominal withdraw reflex score, whereas the depression level of each rat was quantified using the sucrose preference test, the forced swimming test, and the open field test. The expressions of the P2X7 receptor in the hippocampus, spinal cord, and dorsal root ganglion (DRG) were assessed by Western blotting and quantitative real-time PCR. Furthermore, the distributions of the P2X7 receptor and glial fibrillary acidic protein (GFAP) in the hippocampus and DRG were investigated in immunofluorescent experiments. The expressions of p-ERK1/2 and ERK1/2 were determined using Western blotting. The enzyme-linked immunosorbent assay was utilized to measure the concentrations of IL-1β, TNF-α, and IL-10 in the serum. Our results demonstrate that gallic acid was able to alleviate both pain and depression in the rats under study. Gallic acid also reduced the expressions of the P2X7 receptor and p-ERK1/2 in the hippocampi, spinal cords, and DRGs of these rats. Moreover, gallic acid treatment decreased the serum concentrations of IL-1β and TNF-α, while raising IL-10 levels in these rats. Thus, gallic acid may be an effective novel candidate for the treatment of comorbid visceral pain and depression by inhibiting the expressions of the P2X7 receptor in the hippocampus, spinal cord, and DRG.