Diversity in the human leukocyte antigen (HLA) genes might be associated with disease outcomes - the heterozygote advantage hypothesis. We tested this hypothesis in relation to hepatitis B virus (HBV)-associated hepatocellular carcinoma (HCC). We utilized DNA from >10,000 Taiwanese individuals with current or past HBV infection to examine the association between HLA diversity and critical natural history steps in the progression from HBV infection to HCC. Individuals were classified as homozygotes at a given locus when imputed to carry the same 4-digit allele for the two HLA alleles at that locus. We found that increase in number of homozygous HLA class II loci was associated with an increased risk of chronic HBV infection (P for trend=1.18×10^-7). Among chronic HBV carriers, increase in number of homozygous HLA class II loci was also associated with an increased risk of HBV-associated HCC (P for trend=0.031). For individual HLA loci, HLA-DQB1 homozygosity was significantly associated with HCC risk (adjusted hazard ratio=1.40, 95% confidence interval=1.06-1.84). We also found that zygosity affects risk of HCC through its ability to affect viral control. Homozygosity at HLA class II loci, particularly HLA-DQB1, is associated with a higher risk of HBV-associated HCC.