Air pollution has been reported to be an environmental risk factor for autism spectrum disorder. However, the gut microbiome's role as a potential mediator has not been investigated. We aimed to clarify whether particulate matter with an aerodynamic diameter ≤10μm (PM<sub>10</sub>) and nitrogen dioxide (NO<sub>2</sub>) exposure impact autistic traits through the gut microbiome. Using 170 mother-child pairs, PM<sub>10</sub> and NO<sub>2</sub> exposure levels during pregnancy (1st, 2nd, and 3rd trimesters) and annual residential PM<sub>10</sub> levels at age 2, 4, and 6 years were estimated. Autistic traits and gut microbiome were assessed at age 6 years. The associations of PM<sub>10</sub> or NO<sub>2</sub> exposure, gut microbiome composition, and autistic traits were explored, and mediation analyses of statistically significant findings were also conducted. Exposure to PM<sub>10</sub> during the 1st trimester of pregnancy was associated with increased autistic traits (10.6% change per interquartile range (IQR) increase, 95% confidence interval [CI]: 1.1, 21.0) and with Proteobacteria relative abundance at age 6 years (66.9% change per IQR increase, 95% CI: 21.3, 129.8). First trimester NO<sub>2</sub> exposure was associated with autistic traits (12.1% change, 95% CI: 0.1, 25.5) and Proteobacteria relative abundance at age 6 years (48.1% change, 95% CI: -0.1, 119.6). Proteobacteria relative abundance was related to autistic traits (4.4% change per 2-fold increase, 95% CI: 1.3, 7.5). Relations between PM<sub>10</sub> or NO<sub>2</sub> exposure during the 1st trimester and autistic traits at age 6 years were partially mediated by Proteobacteria (proportion mediated 23.2%, p=0.01 and 16.7%, p=0.06; respectively). PM<sub>10</sub> and possibly NO<sub>2</sub> exposure during early pregnancy may affect autistic traits at age 6 years through the alteration of Proteobacteria abundance.