Plant diversity effects on ecosystem functioning can potentially interact with global climate by altering fluxes of the radiatively active trace gases nitrous oxide (N2O) and methane (CH4). We studied the effects of grassland species richness (1–16) in combination with application of fertilizer (nitrogen:phosphorus:potassium = 100:43.6:83 kg ha−1 a−1) on N2O and CH4 fluxes in a long-term field experiment. Soil N2O emissions, measured over 2 years using static chambers, decreased with species richness unless fertilizer was added. N2O emissions increased with fertilization and the fraction of legumes in plant communities. Soil CH4 uptake, a process driven by methanotrophic bacteria, decreased with plant species numbers, irrespective of fertilization. Using structural equation models, we related trace gas fluxes to soil moisture, soil inorganic N concentrations, nitrifying and denitrifying enzyme activity, and the abundance of ammonia oxidizers, nitrite oxidizers, and denitrifiers (quantified by real-time PCR of gene fragments amplified from microbial DNA in soil). These analyses indicated that plant species richness increased soil moisture, which in turn increased N cycling-related activities. Enhanced N cycling increased N2O emission and soil CH4 uptake, with the latter possibly caused by removal of inhibitory ammonium by nitrification. The moisture-related indirect effects were surpassed by direct, moisture-independent effects opposite in direction. Microbial gene abundances responded positively to fertilizer but not to plant species richness. The response patterns we found were statistically robust and highlight the potential of plant biodiversity to interact with climatic change through mechanisms unrelated to carbon storage and associated carbon dioxide removal.