- Genes of the major histocompatibility complex (MHC) encode proteins that recognize foreign antigens and are thus crucial for immune response. In a population of a single host species, parasite-mediated selection drives MHC allelic diversity. However, in a community-wide context, species interactions may modulate selection regimes because the prevalence of a given parasite in a given host may depend on its prevalence in other hosts. By combining network analysis with immunogenetics, we show that host species infected by similar parasites harbour similar alleles with similar frequencies. We further show, using a Bayesian approach, that the probability of mutual occurrence of a functional allele and a parasite in a given host individual is nonrandom and depends on other host–parasite interactions, driving co-evolution within subgroups of parasite species and functional alleles. Therefore, indirect effects among hosts and parasites can shape host MHC diversity, scaling it from the population to the community level.