Background: A machine learning model was developed to estimate the in-hospital mortality risk after congenital heart disease (CHD) surgery in pediatric patient. Methods: Patients with CHD who underwent surgery were included in the study. A Extreme Gradient Boosting (XGBoost) model was constructed based onsurgical risk stratification and preoperative variables to predict the risk of in-hospital mortality. We compared the predictive value of the XGBoost model with Risk Adjustment in Congenital Heart Surgery-1 (RACHS-1) and Society of Thoracic Surgery-European Association for Cardiothoracic Surgery (STS-EACTS) categories. Results: A total of 24,685 patients underwent CHD surgery and 595 (2.4%) died in hospital. The area under curve (AUC) of the STS-EACTS and RACHS-1 risk stratification scores were 0.748 [95% Confidence Interval (CI): 0.707-0.789, p < 0.001] and 0.677 (95% CI: 0.627-0.728, p < 0.001), respectively. Our XGBoost model yielded the best AUC (0.887, 95% CI: 0.866-0.907, p < 0.001), and sensitivity and specificity were 0.785 and 0.824, respectively. The top 10 variables that contribute most to the predictive performance of the machine learning model were saturation of pulse oxygen categories, risk categories, age, preoperative mechanical ventilation, atrial shunt, pulmonary insufficiency, ventricular shunt, left atrial dimension, a history of cardiac surgery, numbers of defects. Conclusions: The XGBoost model was more accurate than RACHS-1 and STS-EACTS in predicting in-hospital mortality after CHD surgery in China.