Lifespan is one of the main components of life history. Shorter lifespans can be expected in marginal habitats. However, in the case of ectotherms, lifespan typically increases with altitude, even though temperature—one of the main factors to determine ectotherms’ life history—declines with elevation. This pattern can be explained by the fact that a shorter activity time favors survival. In this study, we analyzed how lifespan and other life-history traits of the lizard Psammodromus algirus vary along a 2,200 m elevational gradient in Sierra Nevada (SE Spain). Populations at intermediate altitudes (1,200–1,700 m), corresponding to the optimal habitat for this species, had the shortest lifespans, whereas populations inhabiting marginal habitats (at both low and at high altitudes) lived longest. Therefore, this lizard did not follow the typical pattern of ectotherms, as it also lived longer at the lower limit of its distribution, nor did it show a longer lifespan in areas with optimal habitats. These results might be explained by a complex combination of different gradients along the mountain, namely that activity time decreases with altitude whereas food availability increases. This could explain why lifespan was maximum at both high (limited activity time) and low (limited food availability) altitudes, resulting in similar lifespans in areas with contrasting environmental conditions. Our findings also indicated that reproductive investment and body condition increase with elevation, suggesting that alpine populations are locally adapted.