As past usual diet quality may affect gut microbiome (GM) composition, we examined the association of the Healthy Eating Index (HEI)-2015 assessed 21 and 9 years before stool collection with measures of fecal microbial composition in a subset of the Multiethnic Cohort. A total of 5936 participants completed a validated quantitative FFQ (QFFQ) at cohort entry (Q1, 1993–1996), 5280 at follow-up (Q3, 2003–2008) and 1685 also at a second follow-up (Adiposity Phenotype Study (APS), 2013–2016). All participants provided a stool sample in 2013–2016. Fecal microbial composition was obtained from 16S rRNA gene sequencing (V1–V3 regions). HEI-2015 scores were computed based on each QFFQ. Using linear regression adjusted for relevant covariates, we calculated associations of HEI-2015 scores with gut microbial diversity and 152 individual genera. The mean HEI-2015 scores increased from Q1 (67 (sd 10)) to Q3 (71 (sd 11)) and APS (72 (sd 10)). Alpha diversity assessed by the Shannon Index was significantly higher with increasing tertiles of HEI-2015. Of the 152 bacterial genera tested, seven (Anaerostipes, Coprococcus_2, Eubacterium eligens, Lachnospira, Lachnospiraceae_ND3007, Ruminococcaceae_UCG-013 and Ruminococcus_1) were positively and five (Collinsella, Parabacteroides, Ruminiclostridium_5, Ruminococcus gnavus and Tyzzerella) were inversely associated with HEI-2015 assessed in Q1, Q3 and APS. The estimates of change per unit of the HEI-2015 score associated with the abundance of these twelve genera were consistent across the three questionnaires. The quality of past diet, assessed as far as ∼20 years before stool collection, is equally predictive of GM composition as concurrently assessed diet, indicative of the long-term consistency of this relation.