Genome‐wide association studies (GWAS) have identified several risk loci for nonalcoholic fatty liver disease (NAFLD). Previous studies have largely relied on small sample sizes and have assessed quantitative traits. We performed a case‐control GWAS in the UK Biobank using recorded diagnosis of NAFLD based on diagnostic codes recommended in recent consensus guidelines. We performed a GWAS of 4,761 cases of NAFLD and 373,227 healthy controls without evidence of NAFLD. Sensitivity analyses were performed excluding other co‐existing hepatic pathology, adjusting for body mass index (BMI) and adjusting for alcohol intake. A total of 9,723,654 variants were assessed by logistic regression adjusted for age, sex, genetic principal components, and genotyping batch. We performed a GWAS meta‐analysis using available summary association statistics. Six risk loci were identified (P < 5*10−8) (apolipoprotein E [APOE], patatin‐like phospholipase domain containing 3 [PNPLA3, transmembrane 6 superfamily member 2 [TM6SF2], glucokinase regulator [GCKR], mitochondrial amidoxime reducing component 1 [MARC1], and tribbles pseudokinase 1 [TRIB1]). All loci retained significance in sensitivity analyses without co‐existent hepatic pathology and after adjustment for BMI. PNPLA3 and TM6SF2 remained significant after adjustment for alcohol (alcohol intake was known in only 158,388 individuals), with others demonstrating consistent direction and magnitude of effect. All six loci were significant on meta‐analysis. Rs429358 (P = 2.17*10−11) is a missense variant within the APOE gene determining ϵ4 versus ϵ2/ϵ3 alleles. The ϵ4 allele of APOE offered protection against NAFLD (odds ratio for heterozygotes 0.84 [95% confidence interval 0.78‐0.90] and homozygotes 0.64 [0.50‐0.79]). Conclusion: This GWAS replicates six known NAFLD‐susceptibility loci and confirms that the ϵ4 allele of APOE is associated with protection against NAFLD. The results are consistent with published GWAS using histological and radiological measures of NAFLD, confirming that NAFLD identified through diagnostic codes from consensus guidelines is a valid alternative to more invasive and costly approaches.