Energy efficiency is one of the most important challenges in wireless sensor networks (WSNs) as the sensor nodes are battery-operated devices. Due to inherent resource constraints in WSNs, energy-efficient data transmission and routing to the sink is an important challenge. On the other hand, the clustering mechanism is an important scheme which can significantly enhance network lifetime. Hence, an energy efficient routing scheme with optimal path selection is essential for WSNs. Since clustering is an NP-Hard problem, this paper proposes a cluster-based routing scheme using particle swarm optimization (PSO) and firefly algorithms for WSNs. In the proposed method, the firefly optimization algorithm was aimed to select appropriate and optimal cluster head (CH) nodes based on the residual energy, free buffer, and distance. PSO was employed to create proper clusters based on the minimum distance and higher residual energy. The optimal path between the CHs and Sink node is selected based on a minimum Euclidean distance. The proposed method is analyzed in terms of packet delivery rate (PDR), throughput, number of alive nodes, end-to-end delay, and average routing overhead. The proposed method is tested extensively on different scenarios, varying number of nodes, packet size, and the number of packets and position of sink node. The results are compared with traditional schemes and some extant algorithms to illustrate the excellence of the proposed scheme.