ABSTRACT Objective Prior research has demonstrated that social ostracism not only leads to social withdrawal but also impairs sleep. Good sleep is essential for cognitive function, mental health, and adolescent development. The study utilizes a longitudinal design to explore the bidirectional relationship between social ostracism and sleep quality among junior high school students. Methods Three waves of data were collected at 2‐month intervals. The random intercept cross‐lagged panel model (RI‐CLPM) was used to distinguish the impacts of two forms of social ostracism, neglect and rejection, on sleep quality at both the between‐individual and within‐individual levels. Moreover, the potential mediating role of social media disorder and anxiety was also investigated. Results At the between‐individual level, neglect exhibited a significant negative correlation with sleep quality and a positive correlation with anxiety. Both social media disorder and anxiety were negatively correlated with sleep quality. However, these patterns were not observed for rejection. At the within‐individuals level, social media disorder at T2 significantly mediated the longitudinal relationship between neglect in T1 and sleep quality in T3. Conclusions These findings highlight a type of exclusion‐dependent impairment of social ostracism the distinct impact of neglect, but not rejection, on sleep quality and underscore the mediating role of social media usage function as a buffer agent disorder. This study demonstrated the long‐term effects of social ostracism on sleep, positioning it as a critical and persistent impact of social ostracism on sleep quality, which further demonstrated that social ostracism is an important risk factor affecting sleep quality for adolescent sleep health.