BackgroundMen who have sex with men (MSM) living with HIV suffer from psychosocial pressures and marginalization as a result of being HIV-positive and belonging to a sexual minority group, and self-injury or suicidal ideation are prevalent among this group. Studies have found that both perceived self-stigma and altered executive function is related to self-injury or suicidal ideation. However, the combined contribution of self-stigma and executive function to self-injury or suicidal ideation remains unclear, especially in MSM living with HIV. Therefore, this study is conducted to explore the mechanism of self-injury or suicidal ideation by hypothesizing that executive function plays a mediating role in the relationship between self-stigma and self-injury or suicidal ideation.MethodsWe conducted a cross-sectional survey among 448 MSM living with HIV who were recruited in the HIV clinic of a tertiary general hospital in Changsha, China, from November 2021 to February 2022. A questionnaires survey was adopted to collect sociodemographic and disease-related information and data related to executive function (including working memory, inhibition, and task monitoring), self-stigma, and self-injury or suicidal ideation. Structural equation modeling and bootstrap testing were used to investigate the potential mediating role of executive function in the relationship between self-stigma and suicidal ideation.ResultsThe participants were aged 18–76 years. Those who had ever had self-injury or suicidal ideation accounted for 32.8% of the total. A higher level of self-stigma and poorer executive function were associated with more frequent self-injury or suicidal ideation (p < 0.01). The mediation model analysis showed a good fit (x2/df = 1.07, p = 0.381). The direct effect of self-stigma on self-injury or suicidal ideation (β = 0.346, p < 0.001) and the indirect effect of self-stigma via executive function (β = 0.132, p < 0.001) were significant, with the indirect effect accounting for 27.6% of the total effect.ConclusionsThis study demonstrates that executive function mediates the relationship between self-stigma and self-injury or suicidal ideation among MSM living with HIV. It suggests that future studies targeting enhancing executive function and decreasing self-stigma may reduce self-injury or suicidal ideation among MSM living with HIV.