Piglets are susceptible to infections in early life and around weaning due to rapid environmental and dietary changes. A compelling target to improve pig health in early life is diet, as it constitutes a pivotal determinant of gut microbial colonization and maturation of the host’s immune system. In the present study, we investigated how supplementation of yeast-derived β-glucans affects the gut microbiota and immune function pre-and post-weaning, and how these complex systems develop over time. From day two after birth until two weeks after weaning, piglets received yeast-derived β-glucans or a control treatment orally and were subsequently vaccinated against Salmonella Typhimurium. Faeces, digesta, blood, and tissue samples were collected to study gut microbiota composition and immune function. Overall, yeast-derived β-glucans did not affect the vaccination response, and only modest effects on faecal microbiota composition and immune parameters were observed, primarily before weaning. This study demonstrates that the pre-weaning period offers a ‘window of opportunity’ to alter the gut microbiota and immune system through diet. However, the observed changes were modest, and any long-lasting effects of yeast-derived β-glucans remain to be elucidated.