Infections are recognized as playing a critical role in the risk of psychiatric disorders and suicidal behavior; however, few studies have evaluated the risk of eating disorders. To evaluate the association of hospitalization for infections and treatment with anti-infective agents with the risk of an eating disorder diagnosis. A nationwide, population-based, prospective cohort study of 525 643 girls born from January 1, 1989, to December 31, 2006, and followed up until December 31, 2012, was conducted using individual-level data drawn from Danish longitudinal registers. Data were analyzed from January 15 to June 15, 2018, using survival analysis models and adjusted for age, calendar period, parental educational level, and parental history of psychiatric illness. Hospital admission for infections and prescribed anti-infective agents for infections. The main outcome of interest was diagnosis of an eating disorder (anorexia nervosa, bulimia nervosa, or eating disorder not otherwise specified) in a hospital, outpatient clinic, or emergency department setting. Cox proportional hazards regression models were used to estimate hazard ratios (HRs) and accompanying 95% CIs. The study population consisted of 525 643 adolescent girls: 2131 received a diagnosis of anorexia nervosa (median [range] age, 15.2 [8.6-21.3] years), 711 received a diagnosis of bulimia nervosa (median [range] age, 17.9 [13.4-22.7] years), and 1398 received a diagnosis of an eating disorder not otherwise specified (median [range] age, 15.6 [8.6-21.6] years). A total of 525 643 adolescent girls were followed up for 4 601 720.4 person-years until a mean age of 16.2 years (range, 10.5-22.7 years). Severe infections that required hospitalization were associated with an increased risk of a subsequent diagnosis of anorexia nervosa by 22% (HR, 1.22; 95% CI, 1.10-1.35), bulimia nervosa by 35% (HR, 1.35; 95% CI, 1.13-1.60), and eating disorder not otherwise specified by 39% (HR, 1.39; 95% CI, 1.23-1.57) compared with adolescent girls without hospitalizations for infections. Infections treated with anti-infective agents were associated with an increased risk of a subsequent diagnosis of anorexia nervosa by 23% (HR, 1.23; 95% CI, 1.10-1.37), bulimia nervosa by 63% (HR, 1.63; 95% CI, 1.32-2.02), and eating disorder not otherwise specified by 45% (HR, 1.45; 95% CI, 1.25-1.67) compared with adolescent girls without infections treated with anti-infective agents. The findings suggest that hospital-treated infections and less severe infections treated with anti-infective agents are associated with increased risk of subsequent anorexia nervosa, bulimia nervosa, and eating disorders not otherwise specified and that future studies should investigate whether these associations are causal and identify the exact mechanisms between infections and subsequent inflammatory processes with eating disorders.