Despite the growing evidence pointing to the detrimental effects of air pollution on diabetes mellitus (DM), the relationship remains poorly explored, especially in desert-adjacent areas characterized by high aridity and pollution. We conducted a cross-sectional study with health examination data from over 2.9 million adults in two regions situated in the southern part of the Taklamakan Desert, China. We assessed three-year average concentrations (2018-2020) of particulate matter (PM1, PM2.5, and PM10), carbon monoxide (CO), nitrogen dioxide (NO2), and sulfur dioxide (SO2) through a space-time extra-trees model. After adjusting for various covariates, we employed generalized linear mixed models to evaluate the association between exposure to air pollutants and DM. The odds ratios for DM associated with a 10 µg/m3 increase in PM1, PM2.5, PM10, CO, and NO2 were 1.898 (95% CI: 1.741, 2.070), 1.07 (95% CI: 1.053, 1.086), 1.013 (95% CI: 1.008, 1.018), 1.009 (95% CI: 1.007, 1.011), and 1.337 (95% CI: 1.234, 1.449), respectively. Notably, men, individuals aged ≥50 years, those with lower educational attainment, nonsmokers, and those not engaging in physical exercise displayed more susceptible to the adverse effects of air pollution. Multiple sensitivity analyses confirmed the stability of these findings. Our study provides robust evidence of a correlation between prolonged exposure to air pollution and the prevalence of DM among individuals living in the desert-adjacent areas. This research contributes to the expanding knowledge on the relationship between air pollution exposure and DM prevalence in desert-adjacent areas.