BackgroundHelicobacter pylori (H. pylori) infection is associated with enhanced efficacy of immunotherapy in gastric cancer (GC). However, the mechanisms underlying this enhancement are not fully understood.MethodsWe recruited 218 GC patients, 134 esophageal squamous cell carcinoma (ESCC) patients, and 86 dMMR/MSI-H colorectal cancer (CC) patients and collected their stool and tumor samples to analyze the gut and intratumoral microbiome. We assessed microbial diversity and composition and correlated these findings with clinical outcomes to evaluate the relationship between H. pylori status, microbiome alterations, and immunotherapy efficacy.ResultsH. pylori-positive patients showed higher alpha diversity and unique microbial signatures, which were associated with increased immune-related progression-free survival (irPFS) and overall survival (irOS). In addition, we found that the abundance of 45 gut microbiome species was significantly different between the two groups. The gut microbiome of the H. pylori-positive GC group was enriched with species such as Clostridium leptum, Oscillibacter sp. ER4, and Ruminococcus bromii, which were associated with improved treatment response. However, they predicted poor prognosis in patients with esophageal squamous cell carcinoma and colorectal cancer patients with dMMR/MSI-H. Microbial co-occurrence network revealed significantly distinct interaction patterns among the groups. In addition, we found enhanced l-arginine biosynthesis in the gut microbiome of H. pylori-positive GC. In terms of intratumoral bacteria, we identified two genera, Streptococcus and Granulicatella, that were mutually exclusive with H. pylori infection in GC. Enhanced l-lysine fermentation to acetate and butanoate was observed among intratumoral bacteria, suggesting potential metabolic shifts in the tumor microenvironment. Incorporating H. pylori infection status into the microbiome-based prediction model further improved the accuracy of predicting immunotherapy outcomes in GC.ConclusionThese findings suggest that H. pylori had significant effects on the structure and functional activity of gut and intratumoral microbiome, some of which may affect the efficacy of immunotherapy. The clinical value of H. pylori infection status should be considered when establishing a prediction model for immunotherapy efficacy based on gut microbiome.