Abstract Background The gut microbiota evolves from birth and is in early life influenced by events such as birth mode, type of infant feeding, and maternal and infant antibiotics use. However, we still have a gap in our understanding of gut microbiota development in older children, and to what extent early events and pre-school lifestyle modulate the composition of the gut microbiota, and how this impinges on whole body metabolic regulation in school-age children. Results Taking advantage of the KOALA Birth Cohort Study, a long-term prospective birth cohort in the Netherlands with extensive collection of high-quality host metadata, we applied shotgun metagenomics sequencing and systematically investigated the gut microbiota of children at 6–9 years of age. We demonstrated an overall adult-like gut microbiota in the 281 Dutch school-age children and identified 3 enterotypes dominated by the genera Bacteroides, Prevotella, and Bifidobacterium, respectively. Importantly, we found that breastfeeding duration in early life and pre-school dietary lifestyle correlated with the composition and functional competences of the gut microbiota in the children at school age. The correlations between pre-school dietary lifestyle and metabolic phenotypes exhibited a striking enterotype dependency. Thus, an inverse correlation between high dietary fiber consumption and low plasma insulin levels was only observed in individuals with the Bacteroides and Prevotella enterotypes, but not in Bifidobacterium enterotype individuals in whom the gut microbiota displayed overall lower microbial gene richness, alpha-diversity, functional potential for complex carbohydrate fermentation, and butyrate and succinate production. High total fat consumption and elevated plasma free fatty acid levels in the Bifidobacterium enterotype are associated with the co-occurrence of Streptococcus. Conclusions Our work highlights the persistent effects of breastfeeding duration and pre-school dietary lifestyle in affecting the gut microbiota in school-age children and reveals distinct compositional and functional potential in children according to enterotypes. The findings underscore enterotype-specific links between the host metabolic phenotypes and dietary patterns, emphasizing the importance of microbiome-based stratification when investigating metabolic responses to diets. Future diet intervention studies are clearly warranted to examine gut microbe-diet-host relationships to promote knowledge-based recommendations in relation to improving metabolic health in children.