Background Prior studies have mostly focused on the risk factors for nonsuicidal self-injury (NSSI), but only a few studies have emphasized the related protective factors. The present study examined whether maltreatment and behavioral problems were risk factors for NSSI. Moreover, we also sought to understand whether and how friend support provides a buffer against NSSI. Method A total of 436 adolescents completed self-report surveys that addressed maltreatment, behavioral problems, friend support, and NSSI at three different time points. Results There were significant positive correlations between maltreatment and NSSI. In the mediation analyses, we found that maltreatment was indirectly associated with NSSI via behavioral problems. Friend support demonstrated a long-term buffering effect on NSSI. Specifically, friend support had a protective effect on NSSI not only under high maltreatment levels, but also under high behavioral problem levels. Conclusion These findings contribute to the understanding of the influences of both maltreatment, behavioral problems (risk factors), and friend support (protective factors) on NSSI. In the context of intervention and education, it is important to consider the value of friend support when discussing NSSI.