In Leptinotarsa decemlineata, a final‐instar wandering larva typically undergoes an ontogenetic niche shift (ONS), from potato plant during the foraging stage to its pupation site below ground. Using high‐throughput sequencing of the bacterial 16S ribosomal RNA gene, we determined the hypothesis that the L. decemlineata pupae harbor stage‐specific bacteria to meet the physiological requirements for underground habitat. We identified 34 bacterial phyla, comprising 73 classes, 208 orders, 375 families, and 766 genera in the collected specimens. Microbes across phyla Proteobacteria, Firmicutes, Actinobacteria, and Bacteroidetes were enriched in the pupae, while those in the phylum Proteobacteria, Tenericutes, Firmicutes, and Bacteroidetes dominated in the larvae and adults. A total of 18 genera, including Blastococcus, Corynebacterium_1, Gordonia, Microbacterium, Nocardia, Nocardioides, Rhodococcus, Solirubrobacter, Tsukamurella, Enterococcus, Acinetobacter, Escherichia_Shigella, Lysobacter, Pseudomonas, and Stenotrophomonas, were specifically distributed in pupae. Moreover, soil sterilizing removed a major portion of bacteria in pupae. Specifically, both Enterococcus and Pseudomonas were eliminated in the soil sterilizing and antibiotic‐fed beetle groups. Furthermore, the pupation rate and fresh pupal weight were similar, whereas the emergence rate and adult weight were decreased in the antibiotic‐fed beetles, compared with controls. The results demonstrate that a switch of bacterial communities occurs in the pupae; the pupal‐specific bacteria genera are mainly originated from soil; this bacterial biodiversity improves pupa performance in soil. Our results provide new insight into the evolutionary fitness of L. decemlineata to different environmental niches.