By conservative estimates, microbes make up about 17% of the world’s biomass and are essential for most ecosystem functions. However, the mechanisms driving the variation in microbial species diversity in response to both natural and anthropogenic temperature gradients remain unclear. In this study, we integrate ecological metabolic theory with a community assembly model to predict that microbial community diversity generally follows a unimodal pattern with temperature. The position and magnitude of peak diversity are determined by interaction-driven species sorting acting on variations in the temperature dependence of carbon use efficiency (CUE) and generalist-specialist tradeoff. Specifically, trait sorting across temperatures favours communities with high mean and low variance in species-level CUEs. We provide empirical evidence supporting our qualitative predictions of the unimodal temperature-diversity pattern along the global geological temperature gradient, which peaks at about 10-15 _°_C. Our findings indicate that the response of diversity as well as CUE to temperature of microbial communities can be predicted from relatively feasible life-history trait measurements, paving the way for interlinking microbial community diversity and carbon cycling along spatial and temporal thermal gradients.