Owing to wireless communication's broadcast nature, wireless sensor networks (WSNs) are vulnerable to denial-of-service (DoS) attacks. It is of great importance to design an efficient intrusion detection scheme (IDS) for WSNs. In this study, the authors propose a novel IDS based on energy prediction (IDSEP) in cluster-based WSNs. The main idea of IDSEP is to detect malicious nodes based on energy consumption of sensor nodes. Sensor nodes with abnormal energy consumption are identified as malicious ones. Furthermore, IDSEP is designed to differentiate categories of ongoing DoS attacks based on energy consumption thresholds. The simulation results show that IDSEP detects and recognises malicious nodes effectively.