Human leukocyte antigens (HLAs) are highly polymorphic proteins that initiate immunity by presenting pathogen-derived peptides to T cells. HLA polymorphisms mostly map to the antigen-binding cleft, thereby diversifying the repertoire of self-derived and pathogen-derived peptide antigens selected by different HLA allotypes. A growing number of immunologically based drug reactions, including abacavir hypersensitivity syndrome (AHS) and carbamazepine-induced Stevens-Johnson syndrome (SJS), are associated with specific HLA alleles. However, little is known about the underlying mechanisms of these associations, including AHS, a prototypical HLA-associated drug reaction occurring exclusively in individuals with the common histocompatibility allele HLA-B*57:01, and with a relative risk of more than 1,000 (refs 6, 7). We show that unmodified abacavir binds non-covalently to HLA-B*57:01, lying across the bottom of the antigen-binding cleft and reaching into the F-pocket, where a carboxy-terminal tryptophan typically anchors peptides bound to HLA-B*57:01. Abacavir binds with exquisite specificity to HLA-B*57:01, changing the shape and chemistry of the antigen-binding cleft, thereby altering the repertoire of endogenous peptides that can bind HLA-B*57:01. In this way, abacavir guides the selection of new endogenous peptides, inducing a marked alteration in 'immunological self'. The resultant peptide-centric 'altered self' activates abacavir-specific T-cells, thereby driving polyclonal CD8 T-cell activation and a systemic reaction manifesting as AHS. We also show that carbamazepine, a widely used anti-epileptic drug associated with hypersensitivity reactions in HLA-B*15:02 individuals, binds to this allotype, producing alterations in the repertoire of presented self peptides. Our findings simultaneously highlight the importance of HLA polymorphism in the evolution of pharmacogenomics and provide a general mechanism for some of the growing number of HLA-linked hypersensitivities that involve small-molecule drugs.