In wireless sensor networks (WSNs), optimal energy utilization is one of the most crucial issues which needs special attention. It has been observed from the existing literature that communication among sensor nodes (SNs) consumes more energy than computation. Therefore, an efficient mechanism needs to be designed for energy conservation during communication among different SNs. To address these gaps, we propose a learning automata-based multilevel heterogeneous routing (LA-MHR) scheme for WSNs. In an LA-MHR, S-model-based LA is used for cluster heads (CHs) selection. A base station (BS) is used to allocate the cognitive radio spectrum to selected CHs. Moreover, single-hop communication among different SNs is used as multihop communication. It suffers from energy holes problem in WSNs. Based upon the initial energy of SNs, these are divided into intermediate, advanced, super-intermediate, and super-advanced categories. The performance of LA-MHR is evaluated by varying the locations of BS and heterogeneity parameters of SNs. Extensive simulations are performed to evaluate the performance of LA-MHR. Performance evaluation results show that both the network lifetime and stability of LA-MHR are increased by more than 10% as compared to other competing preexisting protocols such as EHE-LEACH, E-SEP, LA-EEHSC, and MCR.