Climate change is causing extreme heating events and intensifying infectious disease outbreaks. Animals harbour microbial communities, which are vital for their survival and fitness under stressful conditions. Understanding how microbiome structures change in response to infection and warming may be important for forecasting host performance under global change. Here, we evaluated alterations in the microbiomes of several wild Caenorhabditis elegans isolates spanning a range of latitudes, upon warming temperatures and infection by the parasite Leucobacter musarum. Using 16S rRNA sequencing, we found that microbiome diversity decreased, and dispersion increased over time, with the former being more prominent in uninfected adults and the latter aggravated by infection. Infection reduced dominance of specific microbial taxa, and increased microbiome dispersion, indicating destabilizing effects on host microbial communities. Exposing infected hosts to warming did not have an additive destabilizing effect on their microbiomes. Moreover, warming during pre-adult development alleviated the destabilizing effects of infection on host microbiomes. These results revealed an opposing interaction between biotic and abiotic factors on microbiome structure. Lastly, we showed that increased microbiome dispersion might be associated with decreased variability in microbial species interaction strength. Overall, these findings improve our understanding of animal microbiome dynamics amidst concurrent climate change and epidemics. This article is part of the theme issue 'Sculpting the microbiome: how host factors determine and respond to microbial colonization'.