Slope instability can lead to catastrophic consequences. However, predicting slope stability effectively is still challenging because of the complex mechanisms and multiple influencing factors. In recent years, machine learning (ML) has received great attention in slope stability prediction due to its strong nonlinear prediction ability. In this study, an optimum-path forest algorithm based on k-nearest neighbor (OPFk-NN) was used to predict the stability of slopes. First, 404 historical slopes with failure risk were collected. Subsequently, the dataset was used to train and test the algorithm based on randomly divided training and test sets, respectively. The hyperparameter values were tuned by combining ten-fold cross-validation and grid search methods. Finally, the performance of the proposed approach was evaluated based on accuracy, F1-score, area under the curve (AUC), and computational burden. In addition, the prediction results were compared with the other six ML algorithms. The results showed that the OPFk-NN algorithm had a better performance, and the values of accuracy, F1-score, AUC, and computational burden were 0.901, 0.902, 0.901, and 0.957 s, respectively. Moreover, the failed slope cases can be accurately identified, which is highly critical in slope stability prediction. The slope angle had the most important influence on prediction results. Furthermore, the engineering application results showed that the overall predictive performance of the OPFk-NN model was consistent with the factor of safety value of engineering slopes. This study can provide valuable guidance for slope stability analysis and risk management.