Socioeconomic status (SES) is inversely associated with risks of type 2 diabetes (T2D). We investigated if young men's cognitive function, measured by intelligence test scores and educational level, as determinants of SES modified associations between body mass index (BMI) and height with the risk of T2D. 369 989 young men from the Danish Conscription Database born between 1939 and 1959 with information on measured height, weight, intelligence test scores, and education were linked to the Danish National Patient Register. During follow-up from 1977 through 2015, T2D was recorded in 32 188 men. Hazard ratios (HR) and 95% confidence intervals (95% CI) were estimated by Cox regressions. BMIs below-average (z-scores ≤ 0) were not related to risks of T2D. For BMIs above-average (z-scores > 0), positive associations between BMI and T2D were slightly stronger among men with higher intelligence test scores or longer educations than among men with lower levels of these factors (pinteraction-values < 0.004). Irrespective of BMI, incidence rates of T2D were higher among men with low levels of intelligence test score and education. Height was inversely associated with T2D (per z-score, HR = 0.96 (95% CI 0.95-0.97) and the association did not vary by intelligence test scores or education (all pinteraction-values > 0.59). While below-average BMI was not associated with T2D risk, above-average BMIs were and these association were stronger among men with high cognitive function. Nevertheless, T2D risk was higher at lower levels of cognitive function throughout the range of BMI. Height was inversely associated with T2D and it was not modified by cognitive function.