Without therapy, most people infected with human immunodeficiency virus (HIV) ultimately progress to AIDS. Rare individuals ('elite controllers') maintain very low levels of HIV RNA without therapy, thereby making disease progression and transmission unlikely. Certain HLA class I alleles are markedly enriched in elite controllers, with the highest association observed for HLA-B57 (ref. 1). Because HLA molecules present viral peptides that activate CD8(+) T cells, an immune-mediated mechanism is probably responsible for superior control of HIV. Here we describe how the peptide-binding characteristics of HLA-B57 molecules affect thymic development such that, compared to other HLA-restricted T cells, a larger fraction of the naive repertoire of B57-restricted clones recognizes a viral epitope, and these T cells are more cross-reactive to mutants of targeted epitopes. Our calculations predict that such a T-cell repertoire imposes strong immune pressure on immunodominant HIV epitopes and emergent mutants, thereby promoting efficient control of the virus. Supporting these predictions, in a large cohort of HLA-typed individuals, our experiments show that the relative ability of HLA-B alleles to control HIV correlates with their peptide-binding characteristics that affect thymic development. Our results provide a conceptual framework that unifies diverse empirical observations, and have implications for vaccination strategies.