Background: The ‘old friends’ hypothesis posits that reduced exposure to previously ubiquitous microorganisms is one factor involved in the increased rates of allergic diseases. Cytomegalovirus (CMV) may be one of the “old friends” hypothesized to help prevent allergic diseases. We sought to elucidate whether early-life CMV infection is associated with childhood atopy via perturbations of the gut microbiota. Methods: Participants were recruited from a population-based birth cohort (CHILD study) and followed prospectively until age five years in four Canadian cities. A total of 928 participants provided stool microbiome data, urine for CMV testing, skin-prick tests, and questionnaires-based detailed environmental exposures. CMV infection was assessed in the first year of life while the main outcome was defined by persistent sensitization to any allergen at ages 1, 3, and 5 years. Results: Early CMV infection was associated with increased beta and decreased alpha diversity of the gut microbiota. Both changes in diversity measures and early CMV infection were associated with persistent allergic sensitization at age 5 years (aOR= 2.08; 95%CI: 1, 4.33). Mediation analysis demonstrated that perturbation of gut microbial composition explains 30% of the association. Conclusions: Early-life CMV infection is associated with an alteration in the intestinal microbiota, which mediates the effect of the infection on childhood atopy. This work indicates that preventing CMV infection would not put children at increased risk of developing atopy. Rather, a CMV vaccine, in addition to preventing CMV-associated morbidity and mortality, might reduce the risk of childhood allergic diseases.