Microbial populations stochastically generate variants with strikingly different properties, such as virulence or avirulence and antibiotic tolerance or sensitivity. Photorhabdus luminescens bacteria have a variable life history in which they alternate between pathogens to a wide variety of insects and mutualists to their specific host nematodes. Here, we show that the P. luminescens pathogenic variant (P form) switches to a smaller-cell variant (M form) to initiate mutualism in host nematode intestines. A stochastic promoter inversion causes the switch between the two distinct forms. M-form cells are much smaller (one-seventh the volume), slower growing, and less bioluminescent than P-form cells; they are also avirulent and produce fewer secondary metabolites. Observations of form switching by individual cells in nematodes revealed that the M form persisted in maternal nematode intestines, were the first cells to colonize infective juvenile (IJ) offspring, and then switched to P form in the IJ intestine, which armed these nematodes for the next cycle of insect infection.