The human X and Y chromosomes evolved from an ordinary pair of autosomes, but millions of years ago genetic decay ravaged the Y chromosome, and only three per cent of its ancestral genes survived. We reconstructed the evolution of the Y chromosome across eight mammals to identify biases in gene content and the selective pressures that preserved the surviving ancestral genes. Our findings indicate that survival was nonrandom, and in two cases, convergent across placental and marsupial mammals. We conclude that the gene content of the Y chromosome became specialized through selection to maintain the ancestral dosage of homologous X-Y gene pairs that function as broadly expressed regulators of transcription, translation and protein stability. We propose that beyond its roles in testis determination and spermatogenesis, the Y chromosome is essential for male viability, and has unappreciated roles in Turner's syndrome and in phenotypic differences between the sexes in health and disease.