Understanding drivers of genetic diversity at the major histocompatibility complex (MHC) is vitally important for predicting how vertebrate immune defence might respond to future selection pressures and for preserving immunogenetic diversity in declining populations. Parasite-mediated selection is believed to be the major selective force generating MHC polymorphism, and while MHC-based mating preferences also exist for multiple species including humans, the general importance of mate choice is debated. To investigate the contributions of parasitism and sexual selection in explaining among-species variation in MHC diversity, we applied comparative methods and meta-analysis across 112 mammal species, including carnivores, bats, primates, rodents and ungulates. We tested whether MHC diversity increased with parasite richness and relative testes size (as an indicator of the potential for mate choice), while controlling for phylogenetic autocorrelation, neutral mutation rate and confounding ecological variables. We found that MHC nucleotide diversity increased with parasite richness for bats and ungulates but decreased with parasite richness for carnivores. By contrast, nucleotide diversity increased with relative testes size for all taxa. This study provides support for both parasite-mediated and sexual selection in shaping functional MHC polymorphism across mammals, and importantly, suggests that sexual selection could have a more general role than previously thought.