Tumor-infiltrating lymphocytes are associated with the survival of gastric cancer patients. T-cell densities in the tumor and its periphery were previously identified as prognostic T-cell markers for resectable gastric cancer. Immunohistochemistry for 5 T-cell markers, CD3, CD45RO, CD8, FOXP3, and granzyme B was performed on serial sections of N = 251 surgical resection specimens of patients treated with surgery only in the D1/D2 trial. Positive T cells were digitally quantified into tiles of 0.25 mm2 across 3 regions: the tumor center (TC), the inner invasive margin, and the outer invasive margin (OIM). A classification and regression tree model was employed to identify the optimal combination of median T-cell densities per region with cancer-specific survival (CSS) as the outcome. All statistical tests were 2-sided. CD8OIM was identified as the most dominant prognostic factor, followed by FOXP3TC, resulting in a decision tree containing 3 prognostically distinct subgroups with high (Hi) or low (Lo) density of the markers: CD8OIMHi, CD8OIMLo/FOXP3TCHi, and CD8OIMLo/FOXP3TCLo. In a multivariable Cox regression analysis, which included pathological T and N stages, Lauren histologic types, EBV status, microsatellite instability, and type of surgery, the immune subgroups were independent predictors for CSS. CSS was lower for CD8OIMLo/FOXP3TCHi (HR: 5.02; 95% CI: 2.03-12.42) and for CD8OIMLo/FOXP3TCLo (HR: 7.99; 95% CI: 3.22-19.86), compared with CD8OIMHi (P < .0001). The location and density of both CD8+ and FOXP3+ T cells in resectable gastric cancer are independently associated with survival. The combination of CD8OIM and FOXP3TC T-cell densities is a promising stratification factor that should be validated in independent studies.