Routing in the Internet of Things (IoT) renders the protection against various network attacks as any attacker intrudes the routing mechanism for establishing the destructive mechanisms against the network, which insists the essentiality of the security protocols in IoT. Thus, the paper proposes a secure protocol based on an optimization algorithm, Monarch-Earthworm Algorithm (Monarch-EWA), which is the modification of the Monarch Butterfly algorithm using the Earthworm Optimization Algorithm (EWA) in order to render effective security to the network. Initially, the effective nodes are selected using the Deep Convolutional Neural Network (deep CNN) classifier based on the factors, trust and energy of the node, and stochastic gradient descent algorithm trains the deep CNN classifier. The secure nodes are involved in routing for which the secure multipath is chosen optimally using the proposed Monarch-EWA, which chooses the secure multipath based on the factors, energy and trust. The analysis of the proposed method in the presence of attacks, such as black hole, message replicate and distributed denial of service, reveals that the proposed method outperformed the existing methods. The proposed Monarch-EWA protocol acquired the maximal energy, throughput and detection rate of 0.2268 J, 48.2759% and 82.6231%, respectively, with the minimal delay of 0.0959 ms.