Previous predictive models using logistic regression for stillbirth do not leverage the advanced and nuanced techniques involved in sophisticated machine learning methods, such as modeling nonlinear relationships between outcomes. This study aimed to create and refine machine learning models for predicting stillbirth using data available before viability (22-24 weeks) and throughout pregnancy, as well as demographic, medical, and prenatal visit data, including ultrasound and fetal genetics. This is a secondary analysis of the Stillbirth Collaborative Research Network, which included data from pregnancies resulting in stillborn and live-born infants delivered at 59 hospitals in 5 diverse regions across the United States from 2006 to 2009. The primary aim was the creation of a model for predicting stillbirth using data available before viability. Secondary aims included refining models with variables available throughout pregnancy and determining variable importance. Among 3000 live births and 982 stillbirths, 101 variables of interest were identified. Of the models incorporating data available before viability, the random forests model had 85.1% accuracy (area under the curve) and high sensitivity (88.6%), specificity (85.3%), positive predictive value (85.3%), and negative predictive value (84.8%). A random forests model using data collected throughout pregnancy resulted in accuracy of 85.0%; this model had 92.2% sensitivity, 77.9% specificity, 84.7% positive predictive value, and 88.3% negative predictive value. Important variables in the previability model included previous stillbirth, minority race, gestational age at the earliest prenatal visit and ultrasound, and second-trimester serum screening. Applying advanced machine learning techniques to a comprehensive database of stillbirths and live births with unique and clinically relevant variables resulted in an algorithm that could accurately identify 85% of pregnancies that would result in stillbirth, before they reached viability. Once validated in representative databases reflective of the US birthing population and then prospectively, these models may provide effective risk stratification and clinical decision-making support to better identify and monitor those at risk of stillbirth.