The geographic ranges of many species have shifted polewards and uphill in elevation associated with climate warming, leading to increases in species richness at high latitudes and elevations. However, few studies have addressed community-level responses to climate change across the entire elevational gradients of mountain ranges, or at warm lower latitudes where ecological diversity is expected to decline. Here, we show uphill shifts in butterfly species richness and composition in the Sierra de Guadarrama (central Spain) between 1967–1973 and 2004–2005. Butterfly communities with comparable species compositions shifted uphill by 293 m (± SE 26), consistent with an upward shift of approximately 225 m in mean annual isotherms. Species richness had a humped relationship with elevation, but declined between surveys, particularly at low elevations. Changes to species richness and composition primarily reflect the loss from lower elevations of species whose regional distributions are restricted to the mountains. The few colonizations by specialist low-elevation species failed to compensate for the loss of high-elevation species, because there are few low-elevation species in the region and the habitat requirements of some of these prevent them from colonizing the mountain range. As a result, we estimated a net decline in species richness in approximately 90% of the region, and increasing community domination by widespread species. The results suggest that climate warming, combined with habitat loss and other drivers of biological change, could lead to significant losses in ecological diversity in mountains and other regions where species encounter their lower latitudinal-range margins.