Due to the advancement of information and communication technologies, the use of Internet of Things (IoT) devices has increased exponentially. In the development of IoT, wireless sensor networks (WSNs) perform a vital part and comprises of low-cost smart devices for information gathering. However, such smart devices have constraints in terms of computation, processing, memory and energy resources. Along with such constraints, one of the fundamental challenges for WSN is to achieve reliability with the security of transmitted data in a vulnerable environment against malicious nodes. This paper aims to develop an energy-efficient and secure routing protocol (ESR) for intrusion avoidance in IoT based on WSN to increase the network period and data trustworthiness. Firstly, the proposed protocol creates different energy-efficient clusters based on the intrinsic qualities of nodes. Secondly, based on the (k,n) threshold-based Shamir secret sharing scheme, the reliability and security of the sensory information among the base station (BS) and cluster head are achieved. The proposed security scheme presents a light-weight solution to cope with intrusions generated by malicious nodes. The experimental results using the network simulator (NS-2) demonstrate that the proposed routing protocol achieved improvement in terms of network lifetime as 37%, average end-to-end delay as 24%, packet delivery ratio as 30%, average communication cost as 29%, network overhead as 28% and the frequency of route re-discoveries as 38% when compared with the existing work under dynamic network topologies.