We explored a 13-year genetic survey of the major histocompatibility complex (MHC) and neutral loci of the Soay sheep population of St Kilda to test the existence and causes of balancing selection at the MHC. The sheep population experiences demographic fluctuations, partly driven by the nematode Teladorsagia circumcincta. The spatial differentiation detected at the MHC was comparable to that at neutral loci between 1988 and 1996, but significantly lower between 1996 and 2000. The rate of temporal genetic differentiation was higher at the MHC, but within the Eastern heft only. These comparisons of spatial and temporal divergence at MHC and non-MHC loci provide strong evidence of balancing selection at the MHC, acting through spatial and temporal heterogeneity in selection pressure. This heterogeneity could be due to fluctuations in the selection imposed by parasites, either directly, because the prevalence in T. circumcincta varies in space and time, or indirectly, because the fitness costs of infection may vary with resource availability.