Although sertraline has been widely used for chronic prostatitis (CP), the mechanisms are unclear. Herein, we explored the mechanisms of sertraline in treating CP. Network pharmacology methods were used to explore the potential targets and molecular mechanisms. LPS was used to stimulate RWPE-1 cells to construct an in vitro model of CP. An experimental autoimmune prostatitis (EAP) mice model was built. CCK-8 assay, EdU assay, BrdU detection, and Tunel assay were performed to evaluate the proliferation and apoptosis process of cells or tissues, respectively. DCFH-DA and Fluo-4 fluorescence probes were used to detect intracellular ROS and calcium concentrations. Von Frey filaments and open-field tests were utilized to evaluate pain response and depressive-like behavior of mice. Histopathology was evaluated through hematoxylin and eosin staining. RT-qPCR, Western blot, immunofluorescence, and immunohistochemistry were utilized to evaluate the transcription, expression, and location of related proteins. Molecular dynamics (MD) simulation and surface plasmon resonance (SPR) assay were performed to measure the binding capacity of sertraline and related proteins. Through a network pharmacology analysis, 27 potential targets of sertraline for CP were obtained, and 5 key targets (CHRM1, ADRA1B, HTR2B, HTR2A, and TRPV1) were finally identified. Functional experiments suggested that TRPV1 was involved in the proliferation, apoptosis inhibition, and ROS production of LPS-induced RWPE-1 cells. In vitro experiments showed that sertraline significantly inhibited cell proliferation, ROS generation, and transcription of inflammation cytokines of LPS-induced RWPE-1 cells. Additionally, sertraline markedly promoted the apoptosis level of LPS-stimulated RWPE-1 cells and elevated the expression level of BAX while reducing the expression levels of Bcl2 and Caspase-3. MD simulation and SPR assay confirmed the direct binding of sertraline to TRPV1. Moreover, sertraline significantly down-regulated the expression level of TRPV1 and inhibited calcium influx of LPS-induced RWPE-1 cells. TRPV1 agonist (Capsaicin) significantly restored the effects on proliferation, apoptosis, ROS production, and calcium influx of sertraline on LPS-induced RWPE-1 cells. Mice experiments demonstrated that sertraline treatment could reduce pain response, improve depression-like symptoms, and relieve local prostate inflammation of EAP mice, as well as down-regulated the expression level of TRPV1, inhibit the proliferation, and promote apoptosis of prostate tissues in EAP mice. The results revealed the anti-inflammatory effect of sertraline for RWPE-1 cells and EAP mice, and the potential mechanism was regulating the TRPV1 channel. It indicated that sertraline might serve as a complementary anti-inflammatory agent for CP.