This study is aimed at exploring the potential mechanisms of melatonin (MT) in treating chronic prostatitis/chronic pelvic pain syndrome (CP/CPPS) using network pharmacology and experimental study. The target genes of MT were acquired from the Swiss Target Prediction, SuperPred, SEA, and PharmMapper databases, and the CP/CPPS targets were collected based on OMIM, DisGeNET, and GeneCards databases. The intersection of MT and CP/CPPS target genes was analyzed. A PPI network was constructed using Cytoscape to identify core targets. The shared targets underwent GO and KEGG enrichment analyses by Using R software. Molecular docking of MT with core targets was performed using AutoDock and PyMOL. GROMACS software was used for molecular dynamics simulation. And using cell experiments to verify the potential effect of MT in CP/CPPS. Network pharmacology analysis reveals 284 shared targets between MT and CP/CPPS, with AKT1, SRC, HSP90AA1, PTGS2, BCL2L1, ALB, CASP3, NFKB1, HIF1A, and ESR1 identified as key targets. Enrichment analysis indicates that MT affects CP/CPPS through various biological processes, and pathway analysis emphasizes the significance of PI3K-Akt, MAPK, Ras, FoxO, HIF-1, EGFR, and apoptosis pathways. Molecular docking confirms strong binding between MT and core targets. It is worth noting that the molecular dynamics simulation showed that the average binding free energy of AKT1, PTGS2, ALB, HSP90AA1 proteins, and MT was - 26.15, - 29.48, - 18.59, and - 20.09 kcal/mol, respectively. These results indicated that AKT1, PTGS2, ALB, and HSP90AA1 proteins were strongly bound to MT. Cell experiments demonstrate that MT can inhibit the secretion of IL-1β, IL-6, and TNF-α in LPS-induced RWPE-1 cells, alleviate inflammation, and suppress cell apoptosis and oxidative stress. Network pharmacology, molecular docking, molecular dynamics simulation, and cell experiments showed that MT could play a role in CP/CPPS by regulating multiple targets and pathways. These findings provide an important scientific basis for further exploration of the molecular mechanism and clinical application of MT in CP/CPPS treatment and are expected to provide new ideas and directions for the development of novel therapeutic strategies.