Selective forwarding attacks (SFAs) can harm the mission of critical applications such as military surveillance and forest fire monitoring. In these attacks, malicious nodes behave like normal nodes most of the time, but selectively drop sensitive packets, such as a packet that reports on the movement of opposing forces, and therefore, detection of this kind of attack is hard. In this paper, a fully distributed, dynamic, intelligent, lightweight algorithm based on learning automata is proposed in order to defend against the selective forwarding attack. In this algorithm, an overhearing mechanism, along with the learning automata model, is used to select secure routes for forwarding packets in a multi-hop routing algorithm. Each node is equipped with a learning automaton, which helps the node select the next hop for forwarding its data towards the base station. The proposed algorithm is simulated using J-SIM. Simulation results show the superiority of the proposed algorithm over existing algorithms, such as the single path forwarding algorithm, the multi-hop acknowledge?based algorithm, the multi-data?flow algorithm, the multi-path algorithm, and the neighbor watch system?based algorithm, in packet delivery rate, packet drop rate by malicious nodes, communications overhead, and energy consumption.