Wireless sensor network (WSN) is the fastest growing technology that dominates the future world into wireless communication. It is a collection of a number of self-governing sensor nodes responsible to sense, process and manipulate the nodes. The sensor nodes are regulated by a battery where the network gets failed if the battery is dead. Thus, energy is an important factor to be efficiently used. Furthermore, congestion occurs in WSN when the incoming traffic load exceeds the capacity of the network. The major factors that lead to congestion are buffer overflow, varying rates of transmission, packet collision, and many-to-one data transmission. Due to these, the network suffers from packet loss, queuing delay, end-to-end delay, decrease in network lifetime, and increase in energy consumption. Hence, a clustering-based routing protocol is introduced in this paper to improve the performance of the network and reduce congestion. In the proposed method, Power-Efficient Gathering in Sensor Information Systems (PEGASIS) double cluster head with artificial neural network (ANN) is utilized to analyze the overall network lifetime. The proposed technique is comprised of four phases: clustering the network nodes, cluster head (CH) selection, chain formation, and secondary CH (SCH) selection. The sensor nodes are initially clustered with the firefly algorithm in which the cluster heads of each node are elected via an artificial neural network. Meanwhile, chain formation is processed by PEGASIS double cluster head (PDCH) and the SCH is selected through grey wolf optimizer (GWO) to afford equivalent energy utilization between the sensor nodes. The simulation outcomes proved that the proposed method efficiently increases the lifetime of the network and reduces congestion level in WSN.