Internet of Things (IoT) is a ubiquitous network that assists the system to monitor and organize the world by processing, collection, and analysis of produced data by IoT nodes. The IoT is susceptible to numerous attacks, wherein the sinkhole attack is the most destructive one, which affects the communication amongst network devices. The security of the IoT is affected due to the lack of dynamic network topology, centralized control, and network communications, so that the trust-based routing is important. The conventional trust-based routing strategies are ineffective to offer protection against attack and thus, trust management remains a major challenge in routing. This paper proposes a novel technique namely Atom Search Sunflower Optimization (ASSFO) for providing trust-based routing in IoT network. The proposed ASSFO is designed by incorporating Sunflower Optimization (SFO) in Atom Search Optimization (ASO). The method utilizes several trust factors for determining and isolating attacks while optimizing the performance of the network. The trust factors considered in the method include indirect trust, recent trust, integrity factor, direct trust, and availability factor. Moreover, the trusted nodes are selected using the trust factor and further used for secure routing using the proposed ASSFO algorithm. The proposed ASSFO outperformed other methods with maximal energy of 0.908, maximal trust of 0.845, maximal PDR of 0.907, and maximal throughput of 0.909.