The rapid advancement of network technologies and protocols has fueled the widespread endorsement of the Internet of Things (IoT) in numerous domains, including everyday life, healthcare, industries, agriculture, and more. However, this rapid growth has also given rise to numerous security concerns within IoT systems. Consequently, privacy and security have become paramount issues in the IoT framework. Due to the heterogeneous data produced by smart IoT devices, traditional intrusion detection system doesn't work well with IoT system. The massive volume of heterogeneous data has several irrelevant, redundant, and unnecessary features which lead to high computation time and low accuracy of IDS. Therefore, to tackle these challenges, this paper presents a novel metaheuristic-based IDS model for the IoT systems. The chaotic opposition-based Harris Hawk optimization (CO-IHHO) algorithm is used to perform the feature selection of data traffic. The chosen features are subsequently inputted into a machine learning (ML) classifier to detect network traffic intrusions. The performance of the CO-IHHO based IDS model is verified against the BoT-IoT dataset. Experimental findings reveal that CO-IHHO-DT achieves the maximal accuracy of 99.65% for multiclass classification and 100% for binary classification, and minimal computation time of 31.34 sec for multiclass classification and 133.54 sec for binary classification.