With the ulcerative colitis (UC) incidence increasing worldwide, it is of great importance to prevent and treat UC. However, efficient treatment options for UC are relatively limited. Due to the potentially serious adverse effects of existing drugs, there is an increasing demand for alternative candidate resources derived from natural and functional foods. Astragalin (AG) is a type of anti-inflammatory flavonoid, with Moringa oleifera and Cassia alata being its main sources. In this study, we investigated the therapeutic effects of AG on mice with dextran sulfate sodium (DSS)-induced colitis. Our results suggested that AG treatment reduced weight loss and the disease activity index (DAI), prevented colon shortening and alleviated colonic tissue damage. AG treatment reduced the expression of pro-inflammatory cytokines and related mRNAs (such as TNF-α, IL-6, and IL-1β), inhibited colonic infiltration by macrophages and neutrophils, ameliorated metabolic endotoxemia, and improved intestinal mucosal barrier function (increased expression levels of mRNAs such as ZO-1, occludin, and Muc2). Western blot analysis revealed that AG downregulated the NF-κB signaling pathway. Moreover, AG treatment partially reversed the alterations in the gut microbiota in colitis mice, mainly by increasing the abundance of potentially beneficial bacteria (such as Ruminococcaceae) and decreasing the abundance of potentially harmful bacteria (such as Escherichia-Shigella). Ruminococcaceae and Enterobacteriaceae (Escherichia-Shigella) were thought to be the key groups affected by AG to improve UC. Therefore, AG might exert a good anti-UC effect through microbiota/LPS/TLR4/NF-kB-related pathways in mice. The results of this study reveal the anti-inflammatory effect and mechanism of AG and provide an important reference for studying the mechanisms of natural flavonoids involved in preventing inflammation-driven diseases.