Wireless sensor network (WSN) sensor nodes should have adequate energy. Reduced energy usage is essential to maximize the endurance of WSNs. Combining WSN with a more significant energy source, a cluster head (CH), is another effective strategy for extending WSN durability. A CH is dependent on the communication inside and between clusters. A CH’s energy level extends the cluster’s life for the complete WSN. Determining the energy required in WSNs while developing clustering algorithms is challenging. For maintaining energy efficiency in WSNs, this research offers K-medoids with sunflower-based clustering and a cross-layer-based optimal routing approach. An efficient fitness function generated from diverse objectives is used to choose the CH. After CH selection, sunflower optimization (SFO) indicates the best data transmission line to the sink node. The proposed protocol, SFO-CORP, increased the network lifetime by 19.6%, 13.63%, 11.13%, and 4.163% compared to the LEACH, EECRP, FEEC-IIR, and CL-IoT protocols, respectively. The experimental results showed that it performed better for packet delivery ratio, energy consumption, end-to-end delay, network lifetime, and computation efficiency.