Pancreatitis occurs in approximately 4% of patients treated with the thiopurines azathioprine or mercaptopurine. Its development is unpredictable and almost always leads to drug withdrawal. We identified patients with inflammatory bowel disease (IBD) who had developed pancreatitis within 3 months of starting these drugs from 168 sites around the world. After detailed case adjudication, we performed a genome-wide association study on 172 cases and 2,035 controls with IBD. We identified strong evidence of association within the class II HLA region, with the most significant association identified at rs2647087 (odds ratio 2.59, 95% confidence interval 2.07-3.26, P = 2 × 10(-16)). We replicated these findings in an independent set of 78 cases and 472 controls with IBD matched for drug exposure. Fine mapping of the HLA region identified association with the HLA-DQA1*02:01-HLA-DRB1*07:01 haplotype. Patients heterozygous at rs2647087 have a 9% risk of developing pancreatitis after administration of a thiopurine, whereas homozygotes have a 17% risk.