Holometabolous insects undergo a radical anatomical re-organisation during metamorphosis. This poses a developmental challenge: the host must replace the larval gut but at the same time retain symbiotic gut microbes and avoid infection by opportunistic pathogens. By manipulating host immunity and bacterial competitive ability, we study how the host Galleria mellonella and the symbiotic bacterium Enterococcus mundtii interact to manage the composition of the microbiota during metamorphosis. Disenabling one or both symbiotic partners alters the composition of the gut microbiota, which incurs fitness costs: adult hosts with a gut microbiota dominated by pathogens such as Serratia and Staphylococcus die early. Our results reveal an interaction that guarantees the safe passage of the symbiont through metamorphosis and benefits the resulting adult host. Host-symbiont “conspiracies” as described here are almost certainly widespread in holometobolous insects including many disease vectors.