NdFeB material has excellent comprehensive magnetic properties, which plays a crucial role in the field of rare earth magnetic materials, and is one of the important basic materials to support modern high-tech industries. In the production of NdFeB alloys, the control of rare earth elements (REEs) is directly related to the quality and resource utilization efficiency of NdFeB materials. Therefore, the prediction of REEs content in NdFeB alloys is of great research significance and application value for the quality control of products, the enhancement of production efficiency and reduction of energy consumption by the rare earth material industry. In this study, a combination of laser-induced breakdown spectroscopy (LIBS) and random forest (RF) was used to investigate the quantitative analysis of four REEs (Nd, Pr, Tb and Dy) in NdFeB alloys. Firstly, the original LIBS spectra were screened by principal component analysis-mahalanobis distance (PCA-MD). Then, the effects of different data processing methods on the screened LIBS spectra were explored, and next, the feature variables were extracted from the preprocessed spectral data by the variable importance measurement (VIM). In order to further verify the prediction performance of the model, the prediction results of the RF models based on the different methods were compared. Finally, a PCA-VIM-RF calibration model was established on the basis of the optimized spectra, selected feature variables and parameters. Leave-one-out cross validation (LOOCV) was used to optimize the parameters of PCA-MD method, spectral preprocessing method and variable importance thresholds during the construction of the calibration model. The results show that the PCA-VIM-RF model has better prediction performance than the RF calibration model based on the raw spectra. For the PCA-VIM-RF calibration method of Nd, Pr, Tb and Dy elements, the values of R2CV are 0.9991, 0.9998, 0.9986, and 0.9984, respectively, the values of RMSECV are 0.06296%, 0.02788%, 0.04647% and 0.05252%, respectively. The values of R2P are 0.9508, 0.9975, 0.9691 and 0.9457, respectively, and the values of RMSEP are 0.6082%, 0.09205%, 0.5776% and 0.2631%, respectively.The above results indicate that LIBS combined with PCA-VIM-RF algorithm is a promising method for rapid quantitative analysis of REEs in NdFeB alloys without complicated sample preparation, which can provide some new ideas or strategies for the future research, development and quality control of rare earth materials.