A nonlinear and complicated phenomenon of the relationship between urban electricity needs and temperature influences the operation and planning of power systems. Ensuring the effectiveness and reliability of the power supply requires precise prediction of electricity needs in various consumption scenarios. In this study, an innovative method is used to deal with the complex relationship between urban electricity consumption and temperature changes. In this paper, the initial contributions focus on the integration of two powerful techniques: the Modified Boxing Match (MBM) algorithm and the XGBoost model, which is a complex convolutional neural network. The integration of these approaches facilitates the extraction of advanced features and allows nonlinear relationships between electricity consumption and temperature data. One of the notable aspects of this work is the introduction of a new leapfrog rule in the MBM algorithm, which significantly improves local exploration and accelerates convergence, leading to more accurate power demand forecasts. The XGBoost model’s hyperparameters are optimized using MBM to achieve the best possible solution. The proposed MBM algorithm was tested on 23 well-known classical benchmark function methods, and the results indicate that the recommended technique is more accurate and robust. As a dependable and efficient tool for modeling and predicting temperature–electricity needs, the suggested method can be utilized.