Anxiety and depression are very common in tuberculosis (TB) patients and can adversely affect TB treatment adherence, ultimately leading to higher morbidity, mortality and drug resistance. Therefore, the aim of this study was to identify the association among experienced stigma, self-esteem and anxiety and depression, and to further explore whether self-esteem could be a moderator in the association between experienced stigma and anxiety and depression in TB patients. A total of 473 TB patients from Dalian, Liaoning Province, Northeast China participated in a cross-sectional survey. A structured questionnaire was developed to collect data. Hierarchical multiple regression was used to analyze the association among experienced stigma, self-esteem and experienced stigma × self-esteem interaction with anxiety and depression. Simple slope analysis was applied to visualize the interaction. Experienced stigma was positively associated with anxiety (B = 0.307, P < 0.01) and depression (B = 0.277, P < 0.01), and self-esteem was negatively associated with anxiety (B = − 0.215, P < 0.01) and depression (B = − 0.351, P < 0.01) in TB patients. The association between experienced stigma and anxiety was different in the low (1 standard deviation (SD) below the mean, B = 0.376, standard error (SE) = 0.056, P < 0.01) and high (1 SD above the mean, B = 0.228, SE = 0.060, P < 0.01) groups of self-esteem. Additionally, the association between experienced stigma and depression was also different in the low (1 SD below the mean, B = 0.363, SE = 0.053, P < 0.01) and high (1 SD above the mean, B = 0.179, SE = 0.056, P < 0.01) groups of self-esteem. Self-esteem could moderate the association between experienced stigma and anxiety and depression. In addition to reducing experienced stigma, enhancing self-esteem as a way to reduce the impact of experienced stigma on anxiety and depression can also help improve the mental health of TB patients.