Agar oligosaccharide (AOS) is a marine prebiotic with apparent improving health and longevity effects. In this study, the protective effect of AOS on the intestine was evaluated in the sodium dodecyl sulfate (SDS)-induced inflammatory model of male Drosophila. The results showed that AOS used as a nutritional additive in basal food could lengthen the life of SDS-stimulated male Drosophila. Additionally, AOS could alleviate the injuries of SDS to microvilli and mitochondria in male Drosophila midgut epithelial cells. AOS could regulate the relative gene expressions in the antibacterial peptides (AMPs), mTOR pathway and autophagy process, and significantly improved the α-diversity of midgut microbiota and decreased the abundance of Klebsiella aerogenes, a kind of bacteria easily causing infections. Collectively, AOS could ameliorate the intestinal inflammation by modulating the microbiota, and the gene expression of immune and cell autophagy.