Recurrent ulcerative colitis (UC) seriously affects the quality of life of patients. Melatonin affects the alteration of the gut microbiota and can effectively relieve inflammation-associated diseases. In the present study, we determined that melatonin effectively alleviated intestinal inflammation and delayed weight loss in mice. Analysis of ileocecal contents in mice via 16S-rRNA and GC-MS revealed that melatonin could elevate the diversity of the gut microbiota and the abundance of short-chain fatty acids producing bacteria and promote the secretion of butyrate. Subsequently, butyrate negatively regulates the NLRP3-mediated inflammatory signaling pathway to inhibit the secretion of proinflammatory mediators such as caspase-1 and IL-1β to restrict the further development of intestinal inflammation. The NLRP3 expression increased, and the GPR109A expression was reduced significantly in the intestinal tissues of active UC patients, which was also closely related to clinical indicators CRP and ESR closely. However, disrupting the gut microbiota with broad-spectrum antibiotics (ABX) blocks melatonin's role in reducing intestinal inflammation. Collectively, we indicate that melatonin arrests UC in mice by modulating the microbiome and the NLRP3/caspase-1 inflammatory signaling pathways to skew macrophage polarization, which may have potential implications in the development of new approaches to treat acute UC.