Severe, repeated or chronic stress produces negative health outcomes including disruptions of the sleep/wake cycle and gut microbial dysbiosis. Diets rich in prebiotics and glycoproteins impact the gut microbiota and may increase gut microbial species that reduce the impact of stress. This experiment tested the hypothesis that consumption of dietary prebiotics, lactoferrin (Lf) and milk fat globule membrane (MFGM) will reduce the negative physiological impacts of stress. Male F344 rats, postnatal day (PND) 24, received a diet with prebiotics, Lf and MFGM (test) or a calorically matched control diet. Fecal samples were collected on PND 35/70/91 for 16S rRNA sequencing to examine microbial composition and, in a subset of rats; Lactobacillus rhamnosus was measured using selective culture. On PND 59, biotelemetry devices were implanted to record sleep/wake electroencephalographic (EEG). Rats were exposed to an acute stressor (100, 1.5 mA, tail shocks) on PND 87 and recordings continued until PND 94. Test diet, compared to control diet, increased fecal Lactobacillus rhamnosus colony forming units (CFU), facilitated non-rapid eye movement (NREM) sleep consolidation (PND 71/72) and enhanced rapid eye movement (REM) sleep rebound after stressor exposure (PND 87). Rats fed control diet had stress-induced reductions in alpha diversity and diurnal amplitude of temperature, which were attenuated by the test diet (PND 91). Stepwise multiple regression analysis revealed a significant linear relationship between early-life Deferribacteres (PND 35) and longer NREM sleep episodes (PND 71/72). A diet containing prebiotics, Lf and MFGM enhanced sleep quality, which was related to changes in gut bacteria and modulated the impact of stress on sleep, diurnal rhythms and the gut microbiota.