In wireless sensors networks, nodes may be easily captured and act non-cooperatively, for example by not defending forwarding packets in response to their own limited resources. If most of these nodes are obtained by attackers, and an attack by an internal malicious node occurs, the entire network will be paralyzed and not be able to provide normal service. Low power consumption indicates that the rational sensor nodes tend to be very close to the mean; high power consumption indicates that the rational sensor nodes are spread out over a large range of values. This paper offers an active defense model for wireless sensor networks based on evolutionary game theory. We use evolutionary game theory to analyze the reliability and stability of a wireless sensor network with malicious nodes. Adding a defense model into the strategy space of the rational nodes and establishing a preventive mechanism forces the malicious node to abandon the attack and even switch to cooperative strategies. Thus, this paper argues that the stability and reliability of wireless sensor networks can be improved. Numerical experiments were conducted to evaluate the proposed defense model, and these results verified our conclusions based on a theoretical analysis that showed that, compared with the existing algorithms, our approach has lower energy consumption, lower deviation, and a higher probability to quickly switch each node to cooperative strategies.