This paper solves the internet of things (IoT) security issues by introducing a chaotic whale crow (CWC) optimization, which is the integration of chaotic whale optimization algorithm (CWOA) in crow search algorithm (CSA). The framework operates on two crucial aspects: one is to select the secure nodes, and the other is to implement secure routing using the selected trusted nodes. First, the selection of trusted nodes is performed based on trust factors like direct, indirect, forwarding rate, integrity, and availability factors. Then, the selected trusted nodes are adapted for trust-based secure routing, which is optimally performed using the proposed CWC, based on the fitness parameters trust and energy. Finally, the proposed CWC is evaluated, which revealed high performance with a minimal delay of 191.46ms, which shows 14.87%, 7.35%, 6.82%, 4.19%, and 5.74% improved performance compared to existing LaSeR, PM Ipv6, secTrust-RPL RISA, and LSDAR techniques. Similarly, the proposed method obtained the maximal energy of 71.25J and maximal throughput of 129.77kbps.