SummaryWith the convergence of the Internet of Things (IoT), 5G, and artificial intelligence, the number of security violations and disturbances on IoT devices and networks has increased. Traditional intrusion detection systems (IDS) are inadequate to handle and detect attacks. This article proposes an improved critical feature selection (ICFS) algorithm with an ensemble learning (EL) for IDS in IoT‐Message queuing telemetry transport (MQTT) network. The proposed framework includes four major parts: (i) The RPIMQTTSET dataset is created using three raspberry pi devices for generating the regular and attack features. (ii) An ICFS algorithm is proposed to select the optimized features from the original dataset, and the optimized features have been validated with the help of the Tanimoto coefficient. (iii) SMOTETomek is applied for balancing the dataset to improve the detection rate of attacks. (iv) Generation of a K‐fold cross‐validated attack detection model utilizing an EL method such as K‐nearest neighbor, eXtreme Gradient Boosting, and random forest. Experimental results show less computational complexity in selecting features, training, and testing the dataset in the proposed network. The proposed model has training accuracy over 99% and testing accuracy over 92%, and it uses fewer redundant features than previous state‐of‐the‐art methodologies.