Exploring the mediating role of positive mental characters between sleep quality and anxiety and depression, in order to prevent mental health problems among medical university students and promote their mental health development. A study was conducted on students from a medical university, using the Insomnia Severity Index, Chinese College Students Positive Psychological Quality Scale, Generalized Anxiety Disorder Scale, and Patient Health Questionnaire Depression Scale for on-site evaluation. The Process macro program developed by Hayes was used for mediation effect analysis. The development of positive mental characters among male students is better than that of female students, and their tendencies towards anxiety and depression are lower than those of female students; The development of positive mental characters among students aged 19–30 is better than that of students aged 18 and below, and their tendency towards anxiety and depression is lower than that of students aged 18; The development of positive mental characters among only child students is better than that of non only child students; The development of positive mental characters among students born in urban areas is better than that of students born in rural areas. The insomnia index is positively correlated with individual anxiety and depression, and the mediating effect of positive mental characters in the association between sleep quality and anxiety and depression accounts for 10.45% of the total effect. The development of positive mental characters partially mediates the relationship between sleep quality and depression and anxiety. High quality sleep and good positive mental characters can help medical school students alleviate anxiety and depression.