This document proposes a new intrusion detection system (IDS) algorithm to defend against selfish node attacks in mobile ad hoc networks (MANETs). Selfish nodes flood the network with false information and drop packets from other nodes. The proposed IDS identifies selfish node behavior and blocks their activities. Simulation results show the IDS enhances network performance from negligible to 92% and prevents infection from attacks. The IDS is integrated with the AODV routing protocol to detect and eliminate selfish nodes within its transmission range.