Mineral consumption has been suggested to have an impact on gastric cancer (GC) prevention. However, the protective effect of potassium against gastric carcinogenesis remains inconclusive. The causal link between inflammation and cancer is well established. Notably, potassium intake and potassium channels may play certain roles in regulating the production of TNF-α (TNF-α). We aimed to determine whether dietary potassium intake is related to the risk of GC. We further observed whether this association was modified by TNF-α rs1800629. We designed a case–control study comprising 377 GC cases and 756 controls. Information on dietary potassium intake was collected using a semiquantitative food frequency questionnaire. Genotyping was performed by the Affymetrix Axiom Exom 319 Array platform. Unconditional logistic regression models were used to assess associations. A significantly reduced GC risk was found for those who consumed higher dietary potassium levels (OR = 0·63, 95 % CI = 0·45, 0·89, P for trend = 0·009). In the dominant model, we observed a non-significant association between TNF-α rs1800629 and GC risk (OR = 1·01, 95 % CI = 0·68, 1·49). In females, those who were homozygous for the major allele (G) of rs1800629 with a higher intake of dietary potassium exhibited a decreased risk of GC (OR = 0·40, 95 % CI = 0·20, 0·78, P interaction = 0·041). This finding emphasises the beneficial effect of potassium intake on GC prevention. However, this association could be modified by TNF-α rs1800629 genotypes. A greater protective effect was exhibited for females with GG homozygotes and high potassium intake.