Objective Suicidal ideation is an important public health challenge among people living with HIV (PLWH) across the world and in China. HIV stigma, depression, and self-esteem have been associated with suicidal ideation. However, the underlying mechanisms remain not fully understood. Methods Study data were derived from a sample of 465 PLWH in China. Suicidal ideation after HIV diagnosis was used as outcome variable. HIV stigma, depressive symptoms, and self-esteem were measured using reliable instruments and used as predictor, mediator, and moderator, respectively. Mediation and moderated mediation model were used for data analysis. Results 31.6% of PLWH in China had suicidal ideation after HIV diagnosis. The association between perceived HIV stigma and suicidal ideation was partially mediated by depression (indirect effect = 0.02, 95% CI = [0.02, 0.03]) with the path from perceived HIV stigma to depressive symptoms being moderated by self-esteem (interaction effect = − 0.02, 95% CI [− 0.03, − 0.01]). Conclusions Study findings suggested a mediation mechanism of HIV stigma on suicidal ideation through depressive symptoms, and self-esteem might weaken the mediation mechanism by moderating the perceived HIV stigma-depressive symptoms pathway.