Helicobacter pylori (H. pylori) is one of the major causes of gastrointestinal diseases, including gastric cancer. However, the acidic environment of the stomach and H. pylori resistance severely impair the antimicrobial efficacy of oral drugs. Here, a biocompatible chitosan-modified molybdenum selenide (MoSe2@CS) was designed for the simultaneous photothermal treatment of H. pylori infection and gastric cancer. MoSe2@CS showed a photothermal conversion efficiency was as high as 45.7 %. In the H. pylori-infected mice model, MoSe2@CS displayed a high bacteriostasis ratio of 99.9 % upon near-infrared irradiation. The antimicrobial functionality was also proved by transcriptomic sequencing study, which showed that MoSe2@CS combined with NIR laser irradiation modulated the gene expression of a variety of H. pylori bioprocesses, including cell proliferation and inflammation-related pathways. Further gut flora analysis results indicated that MoSe2@CS mediated PTT of H. pylori did not affect the homeostasis of gut flora, which highlights its advantages over traditional antibiotic therapy. In addition, MoSe2@CS exhibited a good photothermal ablation effect and significantly inhibited gastric tumor growth in vitro and in vivo. The comprehensive application of MoSe2@CS in the PTT of H. pylori infection and gastric cancer provides a new avenue for the clinical treatment of H. pylori infection and related diseases.