Males and females age at different rates and have different life expectancies across the animal kingdom, but what causes the longevity "gender gaps" remains one of the most fiercely debated puzzles among biologists and demographers. Classic theory predicts that the sex experiencing higher rate of extrinsic mortality evolves faster aging and reduced longevity. However, condition dependence of mortality can counter this effect by selecting against senescence in whole-organism performance. Contrary to the prevailing view but in line with an emerging new theory, we show that the evolution of sex difference in longevity depends on the factors that cause sex-specific mortality and cannot be predicted from the mortality rate alone. Experimental evolution in an obligately sexual roundworm, Caenorhabditis remanei, in which males live longer than females, reveals that sexual dimorphism in longevity erodes rapidly when the extrinsic mortality in males is increased at random. We thus experimentally demonstrate evolution of the sexual monomorphism in longevity in a sexually dimorphic organism. Strikingly, when extrinsic mortality is increased in a way that favors survival of fast-moving individuals, males evolve increased longevities, thereby widening the gender gap. Thus, sex-specific selection on whole-organism performance in males renders them less prone to the ravages of old age than females, despite higher rates of extrinsic mortality. Our results reconcile previous research with recent theoretical breakthroughs by showing that sexual dimorphism in longevity evolves rapidly and predictably as a result of the sex-specific interactions between environmental hazard and organism's condition.