The genes encoding major histocompatibility (MHC) molecules are among the most polymorphic genes known for vertebrates. Since MHC molecules play an important role in the induction of immune responses, the evolution of MHC polymorphism is often explained in terms of increased protection of hosts against pathogens. Two selective pressures that are thought to be involved are (1) selection favoring MHC heterozygous hosts, and (2) selection for rare MHC alleles by host-pathogen coevolution. We have developed a computer simulation of coevolving hosts and pathogens to study the relative impact of these two mechanisms on the evolution of MHC polymorphism. We found that heterozygote advantage per se is insufficient to explain the high degree of polymorphism at the MHC, even in very large host populations. Host-pathogen coevolution, on the other hand, can easily account for realistic polymorphisms of more than 50 alleles per MHC locus. Since evolving pathogens mainly evade presentation by the most common MHC alleles in the host population, they provide a selective pressure for a large variety of rare MHC alleles. Provided that the host population is sufficiently large, a large set of MHC alleles can persist over many host generations under host-pathogen coevolution, despite the fact that allele frequencies continuously change.