The importance of our inner microbial communities for proper immune responses against invading pathogens is now well accepted, but the mechanisms underlying this protection are largely unknown. In this study, we used Caenorhabditis elegans to investigate such mechanisms. Since very little is known about the microbes interacting with C. elegans in its natural environment, we began by taking the first steps to characterize the C. elegans microbiota. We established a natural-like environment in which initially germfree, wild-type larvae were grown on enriched soil. Bacterial members of the adult C. elegans microbiota were isolated by culture and identified using 16S rRNA gene sequencing. Using pure cultures of bacterial isolates as food, we identified two, Bacillus megaterium and Pseudomonas mendocina, that enhanced resistance to a subsequent infection with the Gram-negative pathogen Pseudomonas aeruginosa. Whereas protection by B. megaterium was linked to impaired egg laying, corresponding to a known trade-off between fecundity and resistance, the mechanism underlying protection conferred by P. mendocina depended on weak induction of immune genes regulated by the p38 MAPK pathway. Disruption of the p38 ortholog, pmk-1, abolished protection. P. mendocina enhanced resistance to P. aeruginosa but not to the Gram-positive pathogen Enterococcus faecalis. Furthermore, protection from P. aeruginosa was similarly induced by a P. aeruginosa gacA mutant with attenuated virulence but not by a different C. elegans-associated Pseudomonas sp. isolate. Our results support a pivotal role for the conserved p38 pathway in microbiota-initiated immune protection and suggest that similarity between microbiota members and pathogens may play a role in such protection.