Diversity-stability relationships in grasslands depend on the environment. Climate change and land degradation potentially alter soil pH and community stability within grassland environments, although it remains unclear how alteration in soil pH affects diversity-stability relationships. From a three-year experiment with acidification and alkalization treatments in three types of grasslands (i.e., desert, typical and meadow grasslands) in Northern China, we found that altered soil pH negatively impacted community biodiversity, especially in desert grasslands. Both soil acidification and alkalization reduced community stability in desert grasslands. Soil alkalization reduced community stability in typical grasslands. Altered soil pH did not affect community stability in meadow grasslands. The reduced community stability by soil acidification in desert grasslands could be attributed to the decreased dominant species stability, whereas the soil alkalization-induced decline of community stability could be attributed to the reducing species asynchrony and dominant species stability. Our results suggest that soil pH-mediated community stability is mainly driven by dominant species stability rather than diversity in desert grassland. Soil nutrients are affected by soil acidification and alkalization and varied among grasslands. Soil acidification enhanced nutrient availability and soil alkalization reduced soil total nutrients, both of which were negatively correlated with soil pH in desert grassland. Such changes in soil nutrients were associated with species asynchrony and then indirectly affected community stability, indicating the importance of soil nutrients in driving community stability. Our study suggests that drier grasslands might face greater stability risks and challenges than wetter grasslands under altered soil pH across spatial gradients of semiarid grasslands.