Due to the mobility and frequent topology changes, routing the data poses a challenging issue in the Internet of Things (IoT). Security poses a fundamental requirement factor in most IoT applications particularly, secure routing among the IoT nodes. The aim of this paper is to develop secure routing in IoT with minimal delay, minimal energy consumption and high throughput. Thus, a new algorithm, named Rider Foraging Optimization algorithm (RFO) is designed by the incorporation of standard Rider Optimization algorithm (ROA) and Bacterial Foraging optimization algorithm (BFO) that render an optimal solution, which is the optimal path for transmitting the information. Initially, the trust of the nodes is evaluated and the cluster head (CH) is chosen based on Low-Energy Adaptive Clustering Hierarchy (LEACH) protocol to securely transmit the data. Then, the proposed RFO algorithm selects the optimal path using the fitness factors, such as trust, energy, and delay constraints. The results revealed that the energy consumption of the nodes is reduced and the lifetime of the network is enhanced through the implementation of the proposed RFO, which attained a maximal throughput of 1, and minimal delay and energy consumption of 0.1169 and 0.0002, respectively.