Energy consumption, secure connection of Sensor Nodes (SNs), and their performance analysis play a major role in Wireless Sensor Networks (WSNs) research. Increased case use of various Internet of Things (IoT) applications has led to the development of complicated networks. To address the threats and security issues faced in complicated WSNs, a novel combined feature selection method known as the Fast Correlation-based Feature Selection (FCBFS) with XG-Boost has been proposed for the NSL-KDD intrusion detection benchmark dataset. It helps in the selection of the best features in a cluster-based WSN before the classification step. Five popular machine learning-based classifiers, namely decision tree, random forest, Naïve Bayes, extra tree, and XG-Boost, are used for the development of a robust intrusion detection system in WSN and its IoT applications. The effectiveness and robustness of the developed ensemble methods have been checked using classification accuracy, precision, recall, and F-score. XG-Boost classifier along with the FCBFS process has performed best with a classic accuracy, precision, recall, and F-score up to 99.84%, 99.83%, 99.84%, and 99.82% on multiple runs. Upon comparison with the existing state-of-the-art work in this field, the proposed work has outperformed. Results show that, in contrast to the previous filter approaches, our proposed process can successfully minimize the number of features while maintaining a high classification precision and recognition rate. It further tends to lower the overall energy required by sensor nodes during attack detection, hence extending the network lifetime and usefulness to a sufficient time frame.