Histone lysine demethylases (KDMs) have been reported in various malignances, which affect transcriptional regulation of tumor suppressor or oncogenes. However, the relationship betweenKDMs and formation of tumor microenvironment (TME) in gastric cancer (GC) remain unclear and need to be comprehensively analyzed.In the present study, 24 KDMs were obtained and consensus molecular subtyping was performed using the "NMF" method to stratify TCGA-STAD into three clusters. The ssGSEA and CIBERSORT algorithms were employed to assess the relative infiltration levels of various cell types in the TME. The KDM_score was devised to predict patient survival outcomes and responses to both immunotherapy and chemotherapy.ThreeKDMgenes-related molecular subtypes were Figured out in GC with distinctive clinicopathological and prognostic features. Based on the robustKDMgenes-related risk_score and nomogram, established in our work, GC patients’ clinical outcome can be well predicted. Furthermore, lowKDMgenes-related risk_score exhibited the more effective response to immunotherapy and chemotherapy.This study characterized threeKDMgenes-related TME pattern with unique immune infiltration and prognosis by comprehensively analyses of transcriptomic profiling. Risk_score was also built to help clinicians decide personalized anticancer treatment for GC patients, including in prediction of immunotherapy and chemotherapy response for patients.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12885-023-10923-1.