In this study, the effect of 14 years of GE exclusion in a desert grassland on soil microbial community diversity and metabolites was examined. GE changed the bacterial community structure, the alpha diversity of the bacterial community, and the total phosphorus (TP) and total potassium (TK) content in the soil. More specifically, the relative abundance of Actinobacteria, Proteobacteria, and Chloroflexi increased with GE. In contrast, the relative abundance of Acidobacteria was higher during grazing (G), so it is believed that soil bacteria adapt to environmental changes. Both amino acid and carbohydrate metabolism were enhanced, while lipid metabolism was decreased under GE. It was concluded that GE could trigger changes in both bacterial diversity and soil metabolites, increase the energy supply, and regulate ecosystem function. Consequently, GE would have positive effects on the restoration of desert grasslands by altering the soil microbial community. This work provides new insights into the response of soil microbes to GE.