To prevent large-scale water inrush accidents during the excavation process of a water-rich tunnel, a method, based on a random forest (RF) algorithm, for predicting the hazard level of water inrush is proposed. By analyzing hydrogeological conditions, six factors were selected as evaluating indicators, including stratigraphic lithology, inadequate geology, rock dip angle, negative terrain area ratio, surrounding rock grade, and hydrodynamic zonation. Through the statistical analysis of 232 accident sections, a dataset of water inrush accidents in water-rich tunnels was established. We preprocessed the dataset by detecting and replacing outliers, supplementing missing values, and standardizing the data. Using the RF model in machine learning, an intelligent prediction model for the hazard of water inrush in water-rich tunnels was established through the application of datasets and parameter optimization processing. At the same time, a support vector machine (SVM) model was selected for comparison and verification, and the prediction accuracy of the RF model reached 98%, which is higher than the 87% of the SVM. Finally, the model was validated by taking the water inrush accident in the Yuanliangshan tunnel as an example, and the predicted results have a high degree of consistency with the actual hazard level. This indicates that the RF model has good performance when predicting water inrush in water-rich tunnels and that it can provide a new means by which to predict the hazard of water inrush in water-rich tunnels.