Gastric cancer adversely affects nutrition and immunity, while increasing the risk of tuberculosis (TB). This study investigated the incidence and risk factors for TB in gastric cancer patients who had undergone gastrectomy or endoscopic submucosal dissection (ESD). This retrospective cohort study was conducted using Korean national insurance claims data. We defined three study groups (total gastrectomy, subtotal gastrectomy, and ESD) of patients diagnosed with gastric cancer plus a cancer-free control group. The latent TB infection (LTBI) screening status, TB incidence, and potential confounders in each cohort were analyzed, and the risk of TB was analyzed using a Cox proportional hazard model. LTBI tests were performed in less than 1% of all patients, and the TB incidence rates were 473.8, 287.4, 199.4, 111.1 events/100,000 person-years in the total gastrectomy, subtotal gastrectomy, ESD, and control cohorts, respectively. Compared to the control cohort, the total gastrectomy cohort showed the highest hazard ratio (HR) for TB incidence (HR: 2.896, 95% CI: 2.559-2.337), while the ESD cohort showed a significantly increased risk (HR: 1.578, 95% CI: 1.957-1.980). Age, body mass index, and lack of exercise were risk factors in all cohorts. Comorbidities were also considered risk factors, depending on the cohort type. Patients who underwent gastrectomy or ESD had an increased risk of TB, and this risk was correlated with the scope of gastrectomy. Considering the low rate of LTBI diagnostic tests and increased risk of TB in the study cohorts, more specific and practical guidelines for TB management are required for gastric cancer patients.