Sex determination is a fundamental biological process, yet its mechanisms are remarkably diverse(1,2). In vertebrates, sex can be determined by inherited genetic factors or by the temperature experienced during embryonic development(2,3). However, the evolutionary causes of this diversity remain unknown. Here we show that live-bearing lizards at different climatic extremes of the species' distribution differ in their sex-determining mechanisms, with temperature-dependent sex determination in lowlands and genotypic sex determination in highlands. A theoretical model parameterized with field data accurately predicts this divergence in sex-determining systems and the consequence thereof for variation in cohort sex ratios among years. Furthermore, we show that divergent natural selection on sex determination across altitudes is caused by climatic effects on lizard life history and variation in the magnitude of between-year temperature fluctuations. Our results establish an adaptive explanation for intra-specific divergence in sex-determining systems driven by phenotypic plasticity and ecological selection, thereby providing a unifying framework for integrating the developmental, ecological and evolutionary basis for variation in vertebrate sex determination.