We aimed to explore the association between aberrant DNA methylation of the O(6)-methylguanine-DNA methyltransferase (MGMT) and human mutL homolog 1 (hMLH1) genes with gastric cancer. A total of 283 gastric cancer patients who were confirmed by pathological diagnosis were included in our study. Aberrant DNA methylation of MGMT and hMLH1 were detected. The proportions of DNA hypermethylation in MGMT and hMLH1 in cancer tissues were significantly higher than those in remote normal-appearing tissues. The DNA hypermethylation of MGMT was correlated with the tumor-necrosis-metastasis stage in gastric cancer tissues. Results showed that individuals with gastric cancer in the N1 and M1 stages had a significantly higher risk of DNA hypermethylation of MGMT in cancer tissues [odds ratio (OR) = 1.97, 95% confidence interval (CI) = 1.15-3.37 for the N1 stage; OR (95%CI) = 5.39 (2.08-14.98) for the M1 stage]. In conclusion, we found that aberrant hypermethylation of MGMT could be a predictive biomarker for detecting gastric cancer.