Extending the lifetime of wireless sensor networks (WSNs) and minimizing energy costs are the two most significant concerns for data transmission. Sensor nodes are powered by their own battery capacity, allowing them to perform critical tasks and interact with other nodes. The quantity of electricity saved from each sensor together in a WSN has been strongly linked to the network’s longevity. Clustering conserves the most power in wireless transmission, but the absence of a mechanism for selecting the most suitable cluster head (CH) node increases the complexity of data collection and the power usage of the sensor nodes. Additionally, the disparity in energy consumption can lead to the premature demise of nodes, reducing the network’s lifetime. Metaheuristics are used to solve non-deterministic polynomial (NP) lossy clustering problems. The primary purpose of this research is to enhance the energy efficiency and network endurance of WSNs. To address this issue, this work proposes a solution where hybrid particle swarm optimization (HPSO) is paired with improved low-energy adaptive clustering hierarchy (HPSO-ILEACH) for CH selection in cases of data aggregation in order to increase energy efficiency and maximize the network stability of the WSN. In this approach, HPSO determines the CH, the distance between the cluster’s member nodes, and the residual energy of the nodes. Then, ILEACH is used to minimize energy expenditure during the clustering process by adjusting the CH. Finally, the HPSO-ILEACH algorithm was successfully implemented for aggregating data and saving energy, and its performance was compared with three other algorithms: low energy-adaptive clustering hierarchy (LEACH), improved low energy adaptive clustering hierarchy (ILEACH), and enhanced PSO-LEACH (ESO-LEACH). The results of the simulation studies show that HPSO-ILEACH increased the network lifetime, with an average of 55% of nodes staying alive, while reducing energy consumption average by 28% compared to the other mentioned techniques.