Little is known regarding the association between intestinal motility patterns and cognitive function in individuals who are baseline cognitively healthy. The gut microbiome may contribute to the association. We examined the association between bowel movement (BM) pattern and cognitive function and explored the role of the gut microbiome in explaining this association. In this prospective study, we leveraged 3 cohort studies, Nurses' Health Study (NHS), NHSII, and Health Professionals Follow-Up Study (HPFS). Participants reported BM frequency and subjective cognitive function. In a subset of NHSII participants, we assessed cognitive function using an objective neuropsychological battery. We profiled the gut microbiome in a subset of participants using whole-genome shotgun metagenomics. General linear models, Poisson regression, and logistic regression were used to quantify the association of BM frequency with different cognitive measurements. We followed 112,753 men and women (women: 87.6%) with a mean age of 67.2 years at baseline (NHS: 76 years, NHSII: 59 years, HPFS: 75 years) for a median follow-up of 4 years (NHSII and HPFS: 4 years, NHS: 2 years). Compared with those with BM once daily, participants with BM frequency every 3+ days had significantly worse objective cognitive function, equivalent to 3.0 (95% confidence interval [CI],1.2-4.7) years of chronological cognitive aging. We observed similar J-shape dose-response relationships of BM frequency with the odds of subjective cognitive decline and the likelihood of having more subsequent subjective cognitive complaints (both p nonlinearity < 0.001). BM frequencies of every 3+ days and ≥twice/day, compared with once daily, were associated with the odds ratios of subjective cognitive decline of 1.73 (95% CI 1.60-1.86) and 1.37 (95% CI 1.33-1.44), respectively. BM frequency and subjective cognitive decline were significantly associated with the overall gut microbiome configuration (both p < 0.005) and specific microbial species in the 515 participants with microbiome data. Butyrate-producing microbial species were depleted in those with less frequent BM and worse cognition, whereas a higher abundance of proinflammatory species was associated with BM frequency of ≥twice/day and worse cognition. Lower BM frequency was associated with worse cognitive function. The gut microbial dysbiosis may be a mechanistic link underlying the association.