The objective of this study is to investigate the efficacy of behavioral activation (BA), a novel psychological intervention, in ameliorating psychological distress and anxiety symptoms among patients diagnosed with esophageal and gastric cancer, as well as the mediating role of self-efficacy between BA and psychological distress. A total of 139 patients diagnosed with esophageal and gastric cancer were recruited in China from March 2023 to October 2023 and randomly assigned to either the BA plus care as usual group (BA+CAU group) or the care as usual group (CAU group). Pre- and post-intervention questionnaires, including the Psychological Distress Thermometer (DT), Generalized anxiety disorder 7-item (GAD-7) Scale, General Self-Efficacy Scale (GSES) and the activation subscale of Behavioral Activation for Depression Scale (BADS-A), were administered. Generalized estimating equation analyses revealed that, compared to usual care alone, combining BA with usual care significantly ameliorated psychological distress, anxiety as well as improved self-efficacy and activation. The mediation analysis revealed that self-efficacy served as a mediator in the relationship between activation and psychological distress. BA primarily based on telephone or WeChat can not only directly ameliorates psychological distress and anxiety symptoms in patients with esophageal cancer and gastric cancer but also indirectly alleviates psychological distress by enhancing self-efficacy. The study also demonstrates the potential of BA in cancer patients, a skill that can be effectively acquired by primary care workers without specialized training and implemented more flexible. NCT06348940.