The objective is to investigate the relationship between endoscopic resection in gastric cancer and incidence of tuberculosis (TB) infection. A nationwide population-based matched cohort study using data retrieved from Korea?s National Health Insurance Corporation Research Database was performed with data from 2013 to 2019. We identified 90,886 gastric cancer patients who received gastrectomy and 46,759 gastric cancer patients who received endoscopic resection. Each group was matched with normal subjects from the matched cohort for age, sex, comorbidities and index year of the procedure at a 1:1 ratio. Risk of TB according to comorbidities were examined by adjusted hazard ratio. Among 46,759 gastric cancer patients those who received endoscopic resection, 140 patients developed TB infection, with an incidence of 0.98 per 1,000 person-years. When the overall incidence was adjusted by sex and age, incidence of TB infection in endoscopic resection group was not significantly higher than the matched cohort (IRR 0.95, 95% CI 0.75-1.19). In gastrectomy group, overall incidence was significantly higher than the matched cohort when the matched cohort (IRR 1.69, 95% CI 1.43-1.99). Age, chronic obstructive pulmonary disease, and chronic kidney disease were significant risk factors for TB infection after endoscopic resection in a multivariate analysis. Risk of TB infection after gastrectomy is significantly higher and risk of TB after endoscopic resection is not significantly higher compared to the matched cohort.