Dietary fibre is essential in shaping the gut microbiota of pigs, affecting their health. We hypothesised that different fibre fermentability in diets could impact the faecal microbiota and pathogen levels in pigs. The sows were fed diets supplemented with sugar beet pulp (SBP) or lignocellulose (LNC). Faecal samples from sows during gestation and lactation and from their piglets were subjected to DNA extraction, 16SrDNA sequencing and qPCR. In sows, Clostridium perfringens concentration was higher in LNC vs. SBP group at baseline. Seven days ante-partum, Escherichia coli-Hafnia-Shigella and segmented filamentous bacteria (SFB) were higher in LNC vs. SBP (p = 0.015, p = 0.005, respectively), while Clostridioides difficile was higher in sows fed SBP vs. LNC (p = 0.029). One week post-partum, E. coli-Hafnia-Shigella and SFB were higher in LNC vs. SBP (p = 0.035, p = 0.032, respectively). Microbiota sequencing analysis showed age-based clustering of the piglets. In one-week-old piglets, the counts of C. difficile and TcdA were higher in LNC vs. SBP (p = 0.001 and p = 0.002, respectively). In 21-day-old piglets, C. perfringens was higher in LNC vs. SBP (p = 0.018). At weaning, E. coli-Hafnia-Shigella and C. perfringens were higher in piglets from LNC vs. SBP (p = 0.004 and p = 0.037, respectively). Two days post-weaning, C. perfringens was higher in piglets from LNC vs. SBP (p = 0.034). One week postweaning, Streptococcus suis was higher in piglets from SBP vs. LNC (p = 0.002). Two weeks post-weaning, E. coli-Hafnia-Shigella was higher in piglets from LNC vs. SBP (p = 0.048). Maternal dietary fibre influences early microbial programming in piglets, potentially affecting their susceptibility to gut pathogens. These findings highlight the importance of sow nutrition in shaping offspring resilience to infections and health.