Objective: Childhood trauma and stressful life events have been identified as risk factors for the development of depression. However, little is known about the potential cognitive mechanisms underlying these associations. This study aims to investigate the associations among childhood trauma, stressful life events, and depression and to test a mediating model to examine the roles of cognitive flexibility in these associations. Method: First-year university students (n = 2627; Mage = 18.29, SDage = .86) were recruited from a medical university in Guangzhou, China. A total of 1,600 (60.9%) females and 1,027 (39.1%) males participated in the survey. Participants were administered self-report measures assessing childhood trauma, stressful life events, cognitive flexibility, and depression. Results: Childhood trauma and stressful life events were both negative predictors of cognitive flexibility (β = −.32, β = −.19, respectively; ps < .01), which in turn was a negative predictor of depression (β = −.50, p < .01). Cognitive flexibility partially mediated the relationship between childhood trauma and depression (with the indirect effect = .161, 95% confidence interval, CI [.139, .185]) as well as the relationship between stressful life events and depression (with the indirect effect = .097, 95% CI [.078, .118]). Conclusions: This study reveals that childhood trauma and stressful life events not only have a direct effect on depression but also increase individuals’ risk of depression by decreasing their cognitive flexibility. These findings shed light on the possible potential mechanism underlying the suicide process and highlight the important role of cognitive flexibility in suicide prevention and intervention.