Animals’ gut microbiomes affect a wide array of biological processes including immunity and protection from pathogens. However, how the microbiome changes due to infection by parasites is still largely unknown, as is how the microbiome changes in hosts that differ in their susceptibility to parasites. To investigate this, we exposed two slug species of differing susceptibility to the parasitic nematode Phasmarhabditis hermaphrodita (Deroceras reticulatum is highly susceptible and Ambigolimax valentianus resistant to the nematode) and profiled the gut microbiota after 7 and 14 days. Before infection, both slug species’ microbiota was dominated by similar bacterial genera: Pseudomonas (by far the most abundant), Sphingobacterium, Pedobacter, Chryseobacterium, and Flavobacterium. In the resistant host A. valentianus, there was no significant change in the bacterial genera after infection, but in D. reticulatum, the bacterial profile changed, with a decrease in the abundance of Pseudomonadaceae and an increase in the abundance of Flavobacteriaceae and Sphingobacteriaceae after 7 days postinfection. This suggests nematode infection causes dysbiosis in hosts that are susceptible to infection, but the microbiome of resistant species remains unaltered. In summary, the regulation of the immune system is tightly linked with host survival, and nematode infection can alter the microbiome structure.