Manipulating gut microbes may improve mental health. Prebiotics are indigestible compounds that increase the growth and activity of health‐promoting microorganisms, yet few studies have examined how prebiotics affect CNS function. Using an acute inescapable stressor known to produce learned helplessness behaviours such as failure to escape and exaggerated fear, we tested whether early life supplementation of a blend of two prebiotics, galactooligosaccharide (GOS) and polydextrose (PDX), and the glycoprotein lactoferrin (LAC) would attenuate behavioural and biological responses to stress later in life. Juvenile, male F344 rats were fed diets containing either GOS and PDX alone, LAC alone, or GOS, PDX and LAC. All diets altered gut bacteria, while diets containing GOS and PDX increased Lactobacillus spp. After 4 weeks, rats were exposed to inescapable stress, and either immediately killed for blood and tissues, or assessed for learned helplessness 24 h later. Diets did not attenuate stress effects on spleen weight, corticosterone and blood glucose; however, all diets differentially attenuated stress‐induced learned helplessness. Notably, in situ hybridization revealed that all diets reduced stress‐evoked cfos mRNA in the dorsal raphe nucleus (DRN), a structure important for learned helplessness behaviours. In addition, GOS, PDX and LAC diet attenuated stress‐evoked decreases in mRNA for the 5‐HT 1A autoreceptor in the DRN and increased basal BDNF mRNA within the prefrontal cortex. These data suggest early life diets containing prebiotics and/or LAC promote behavioural stress resistance and uniquely modulate gene expression in corresponding circuits.