Carbon emissions play a significant role in shaping social policy-making, industrial planning, and other critical areas. Recurrent neural networks (RNNs) serve as the major choice for carbon emission prediction. However, year-frequency carbon emission data always results in overfitting during RNN training. To address this issue, we propose a novel model that combines oscillatory particle swarm optimization (OPSO) with long short-term memory (LSTM). OPSO is employed to fine-tune the hyperparameters of LSTM, utilizing an oscillatory strategy to effectively mitigate overfitting and consequently improve the accuracy of the LSTM model. In validation tests, real data from Hainan Province, encompassing diverse dimensions such as gross domestic product, forest area, and ten other relevant factors, are used. Standard LSTM and PSO-LSTM are selected in the control group. The mean absolute error (MAE), root mean square error (RMSE), and mean absolute percentage error (MAPE) are used to evaluate the performance of these methods. In the test dataset, the MAE of OPSO-LSTM is 117.708, 65.72% better than LSTM and 29.48% better than PSO-LSTM. The RMSE of OPSO-LSTM is 149.939, 68.52% better than LSTM and 41.90% better than PSO-LSTM. The MAPE of OPSO-LSTM is 0.017, 65.31% better than LSTM, 29.17% better than PSO-LSTM. The experimental results prove that OPSO-LSTM can provide reliable predictions for carbon emissions.