Accurate PV power prediction is crucial for stable grid operation and rational dispatch. However, due to the instability of PV power generation, PV power prediction still has great challenges. Therefore, an Autoformer model based on secondary decomposition, Bayesian optimization and error correction for PV power prediction. In order to reduce the complexity of the data and fully extract the features, two decomposition methods are employed. First, empirical mode decomposition (EMD) is applied to decompose the PV power series at the first level. Then, the sample entropy (SE) is introduced to measure the complexity of each component, and the variational mode decomposition (VMD) is employed to implement secondary decomposition of the component with the highest complexity. Secondly, a Bayesian optimization algorithm enhanced Autoformer model is developed for predicting each component, and the predicted component results are aggregated to obtain preliminary PV power prediction results. Finally, the preliminary prediction results are error corrected using a least squares support vector machine. A four-month PV dataset from a PV power plant in Hangzhou, China is utilized to validate the effectiveness of the proposed model. The experimental results show that the model after primary decomposition is superior to the single model, and the prediction accuracy is substantially improved after secondary decomposition. The proposed model has the best prediction performance in predicting the PV power for different seasons, which shows good robustness.