This study aims to develop statistical and machine learning methodologies for forecasting yearly electricity consumption in Saudi Arabia. The novelty of this study include (i) determining significant features that have a considerable influence on electricity consumption, (ii) utilizing a Bayesian optimization algorithm (BOA) to enhance the model’s hyperparameters, (iii) hybridizing the BOA with the machine learning algorithms, viz., support vector regression (SVR) and nonlinear autoregressive networks with exogenous inputs (NARX), for modeling individually the long-term electricity consumption, (iv) comparing their performances with the widely used classical time-series algorithm autoregressive integrated moving average with exogenous inputs (ARIMAX) with regard to the accuracy, computational efficiency, and generalizability, and (v) forecasting future yearly electricity consumption and validation. The population, gross domestic product (GDP), imports, and refined oil products were observed to be significant with the total yearly electricity consumption in Saudi Arabia. The coefficient of determination R2 values for all the developed models are >0.98, indicating an excellent fit of the models with historical data. However, among all three proposed models, the BOA–NARX has the best performance, improving the forecasting accuracy (root mean square error (RMSE)) by 71% and 80% compared to the ARIMAX and BOA–SVR models, respectively. The overall results of this study confirm the higher accuracy and reliability of the proposed methods in total electricity consumption forecasting that can be used by power system operators to more accurately forecast electricity consumption to ensure the sustainability of electric energy. This study can also provide significant guidance and helpful insights for researchers to enhance their understanding of crucial research, emerging trends, and new developments in future energy studies.