Obesity is a known risk factor for gastric cancer. However, the relationship between serum lipids and gastric cancer risk has not been fully established. We investigated the relationship between serum cholesterol levels and gastric cancer risk using a nationwide population cohort. Adults who received health care screening in 2009 from the Korean National Health Insurance Service were enrolled. Gastric cancer risk in relation to quartiles of high-density lipoprotein cholesterol (HDL-C), low-density lipoprotein cholesterol (LDL-C), and total cholesterol (TC) were compared according to sex, using adjusted hazard ratios (aHRs) with 95% confidence intervals (CIs). Among 9690,168 subjects enrolled, 92,403 gastric cancer cases were diagnosed. Higher HDL-C levels were associated with lower gastric cancer risk in the total population, men, and women (aHR [for the highest quartile] = 0.98 [0.96-0.99, P < .0001], aHR = 0.98 [0.96-1.004, P = .0004], and aHR = 0.91 [0.88-0.94, P < .0001], respectively). HDL-C showed consistent trends regardless of age or statin use. Higher LDL-C levels were also associated with lower gastric cancer risk in the total population (aHR = 0.92 [0.91-0.94], P < .0001) and men (aHR = 0.94 [0.91-0.96], P < .0001), but not in women (P = .4073). A subgroup analysis of LDL-C showed significant interactions with age and statin use (Pinteraction < .0001 and Pinteraction = .0497, respectively). The risk of gastric cancer was higher in subjects with elevated LDL-C levels in the younger group (age < 55, HR [for the highest quartile] = 1.02 [0.99-1.04] in the total population; HR = 1.03 [1.003-1.06] in men), the risk was lower in subjects with elevated LDL-C in the elderly (age ≥ 55, HR = 0.93 [0.91-0.95] in the total population; HR = 0.94 [0.92-0.96] in men). Elevated TC was associated with lower gastric cancer risk in the total population (aHR = 0.95 [0.94-0.97], P < .0001), but not in each sex separately (P = .3922 in men; P = .1046 in women). Overall, higher HDL-C levels may play a protective role in gastric cancer pathogenesis. The association between LDL-C/TC and gastric cancer seems to vary according to sex, age, and statin use. Especially in young males under age 55, high LDL-C and TC levels were associated with higher risk of gastric cancer.