Abstract Background Anorexia nervosa (AN), a serious eating disorder, and inflammatory bowel diseases (IBD) share a number of key symptoms, for example, discomfort during eating and early satiety. Despite the symptom overlap, studies on comorbidity are limited and mostly conducted in relatively small samples. This study investigates the comorbidity of diagnosed AN with IBD, and the subtypes Crohn's disease and ulcerative colitis, in a population‐based sample and explores whether genetic factors could play a role in the overlap. Methods The study included 1,238,813 individuals born in Denmark 1981–2005 selected from the population register (5067 diagnosed with AN and 6947 diagnosed with any IBD), including a subsample of 23,236 individuals with genetic information (4271 with AN and 176 with any IBD). By combining hospital‐based diagnoses recorded in health registers until 2013 with polygenic scores (PGS) of AN and IBD, we investigated possible associations between diagnoses of each disorder, both within individuals and families, and between PGS of one disorder and diagnosis of the other disorder. Analyses were conducted using Cox regression and logistic regression. Results We found that a prior diagnosis of AN was associated with hazard ratios of 1.44 (1.05, 1.97) for any IBD, 1.60 (1.04, 2.46) for Crohn's disease, and 1.66 (1.15, 2.39) for ulcerative colitis, whereas IBD diagnoses were not significantly associated with later AN diagnosis. No significant within‐families associations were observed. We found no associations between AN and IBD using PGS. Conclusions AN was associated with later risk of IBD, Crohn's disease, and ulcerative colitis; however, the reverse was not observed. It is important for clinicians to be aware of this association to evaluate IBD as a differential diagnosis or an emergent condition in patients with AN.