BackgroundThe structure of gut microbiota is highly complex. Insects have ubiquitous associations with intestinal symbiotic bacteria, which play essential roles. Thus, understanding how changes in the abundance of a single bacterium interfere with bacterial interactions in the insect’s gut is important.MethodsHere, we analyzed the effects ofSerratia marcescenson the growth and development of housefly larvae using phage technology. We used 16S rRNA gene sequencing technology to explore dynamic diversity and variation in gut bacterial communities and performed plate confrontation assays to study the interaction betweenS. marcescensand intestinal microorganisms. Furthermore, we performed phenoloxidase activity assay, crawling assay, and trypan blue staining to explore the negative effects ofS. marcescenson housefly larvae’s humoral immunity, motility, and intestinal organization.ResultsThe growth and development of housefly larvae were inhibited after feeding onS. marcescens, and their intestinal bacterial composition changed with increasing abundance ofProvidenciaand decreasing abundance ofEnterobacterandKlebsiella. Meanwhile, the depletion ofS. marcescensby phages promoted the reproduction of beneficial bacteria.ConclusionsIn our study, using phage as a tool to regulate the abundance ofS. marcescens, we highlighted the mechanism by whichS. marcescensinhibits the growth and development of housefly larvae and illustrated the importance of intestinal flora for larval development. Furthermore, by studying the dynamic diversity and variation in gut bacterial communities, we improved our understanding of the possible relationship between the gut microbiome and housefly larvae when houseflies are invaded by exogenous pathogenic bacteria.Graphical AbstractSupplementary InformationThe online version contains supplementary material available at 10.1186/s13071-023-05781-6.