Candida albicans can exist in the mammalian gut as either a commensal or an invasive pathogen. Pande et al. show that passage of wild-type C. albicans through the mouse gastrointestinal tract elicits expression of the transcription factor Wor1, which promotes commensalism. Overexpression of Wor1 enhanced fitness, whereas cells lacking the encoding gene were rapidly depleted. Wor1 was shown to trigger a heritable developmental switch that converted wild-type C. albicans from a white phenotype to a morphologically distinct dark phenotype (termed the gastrointestinally induced transition (GUT)). Transcriptomics also revealed that the GUT cells were functionally specialized for the metabolism of local nutrients in the digestive tract. These data highlight the fact that microorganisms can use distinct developmental programmes to switch between pathogenic and commensal states.