The safety of underground coal mining has always been a global concern, involving the stable supply of energy and stakes in miners’ lives. Lessons learned from historical accidents and transforming into practical experience help reduce the quantity and severity of accidents. In this study, six ensemble learning techniques, including AdaBoost, Extra Trees, GBDT, LightGBM, Random Forest, and XGBoost, were used to investigate the correlation between accident-causing factors and severity. Firstly, 39487 underground coal mine accidents data was obtained from Spain, variables were categorized and coded. To address the extreme class imbalance, a new dataset (2468 cases) was obtained by data sampling from the original database. Subsequently, the new dataset was randomly divided into training sets (75% of the data) and test sets (25% of the data), then the hyperparameters of each model were optimized and configured. Thirdly, the models’ performance was evaluated on the test data by five metrics (accuracy, Cohen’s Kappa, precision, recall, and F1). Finally, accident patterns were derived from the identified variables along with preventive strategies. Results show that tree-based ensemble learning model performs better compared to the boosting model, and the relative importance of seven variables were determined, where previous cause (PC) and material agent (MA) are the most important factors, followed by the miner’s physical activity (PA), age (A), and experience (E), scale (S) and preventive organization (PO) are in the third tier. Furthermore, the type of accident and injury caused by PC were confirmed. Working with hand tools, younger age, lack of experience, small-scale coal mines, and unfit preventive organization increased the risk of accidents. This study not only facilitates the prediction of accident severity but also provides strategies for preventing and mitigating accidents.