Suicidal behaviors are prevalent public health concerns, and we need to improve our predictive ability to better inform prevention efforts. Using nationwide longitudinal Swedish registers, we included 344,490 males and 323,177 females born 1982-1990 with information on genetic liability and environmental exposures from birth to age 16: perinatal variables, parental psychopathology (suicide attempt, substance use disorder, major depression), family status, socioeconomic difficulties, peers' psychopathology, and school grades. We conducted sex-specific analysis and developed data-driven predictive models including risk factors that occurred between ages 0 and 16 using structural equation modeling. In both females and males, the best-fitting models reveal a complex risk pathway to suicide attempt. In females, the model indicates four direct effects on suicide attempt risk: the occurrence of suicide attempt in parents during childhood (β = 0.159, 95% CI: 0.118; 0.199) and adolescence (β = 0.115, 95% CI: 0.077; 0.153), suicide attempt in peers (β = 0.068, 95% CI: 0.057; 0.079), and low academic achievement (β = 0.166, 95% CI: 0.156; 0.175). In males, aggregate genetic liability for suicide attempt (β = 0.130, 95% CI: 0.111; 0.148), suicide attempt in parents during adolescence (β = 0.099, 95% CI: 0.074; 0.124), suicide attempt in peers (β = 0.118, 95% CI: 0.108; 0.129), and low academic achievement (β = 0.61, 95% CI: 0.152; 0.171) were related to later suicide attempt. These factors also acted as mediators to explain the association between environmental exposures in childhood and later suicide attempt. These findings illustrate sex-specific pathways to suicide attempt by including risk factors that occur during the development. Results highlight the importance of genetic and family environment but also the prominent role of academic achievement.