Fungal infections and toxicoses caused by insecticides may alter microbial communities and immune responses in the insect gut. We investigated the effects of Metarhizium robertsii fungus and avermectins on the midgut physiology of Colorado potato beetle larvae. We analyzed changes in the bacterial community, immunity- and stress-related gene expression, reactive oxygen species (ROS) production, and detoxification enzyme activity in response to topical infection with the M. robertsii fungus, oral administration of avermectins, and a combination of the two treatments. Avermectin treatment led to a reduction in microbiota diversity and an enhancement in the abundance of enterobacteria, and these changes were followed by the downregulation of Stat and Hsp90, upregulation of transcription factors for the Toll and IMD pathways and activation of detoxification enzymes. Fungal infection also led to a decrease in microbiota diversity, although the changes in community structure were not significant, except for the enhancement of Serratia. Fungal infection decreased the production of ROS but did not affect the gene expression of the immune pathways. In the combined treatment, fungal infection inhibited the activation of detoxification enzymes and prevented the downregulation of the JAK-STAT pathway caused by avermectins. The results of this study suggest that fungal infection modulates physiological responses to avermectins and that fungal infection may increase avermectin toxicosis by blocking detoxification enzymes in the gut.