Gastrointestinal infections have been linked to changes in the composition and function of gut microbiome and development of inflammatory bowel diseases. We therefore sought to examine the relationship between gastroenteritis and risk of microscopic colitis (MC).We conducted a case-control study of all adult MC patients diagnosed between 1990-2016 in Sweden matched to up to 5 general population controls according to age, sex, calendar year, and county. Cases of MC were identified using SNOMED codes from the ESPRESSO study, a cohort of gastrointestinal pathology reports from all 28 pathology centers in Sweden. We used logistic regression modeling to estimate adjusted odds ratios (aORs) and 95% CIs.Through December of 2016, we matched 13,468 MC cases to 64,479 controls. The prevalence of previous diagnosed gastrointestinal infection was 7.5% among MC patients which was significantly higher than in controls (3.0%, Pcomparison <0.001). After adjustment, gastroenteritis was associated with an increased risk of MC (aOR 2.63; 95%CI=2.42-2.85). Among specific pathogens, Clostridioides difficile (aOR 4.39, 95%CI=3.42-5.63), Norovirus (aOR 2.87, 95%CI=1.66-4.87) and Escherichia species (aOR 3.82, 95%CI=1.22-11.58) but not Salmonella species were associated with an increased risk of MC. The association between gastrointestinal infections and risk of MC was stronger for collagenous subtype (aOR 3.23, 95% CI 2.81-3.70) as compared to lymphocytic colitis (aOR = 2.51, 95% CI 2.28-2.76, Pheterogeneity = 0.005). The associations remained significant after adjustment for immune-mediated conditions and polypharmacy and when compared to unaffected siblings.In a nationwide study, we found that gastrointestinal infection, particularly Clostridioides difficile is associated with an increased risk of subsequent MC.