Since wireless sensor networks are emerging as innovative technologies for realizing a variety of functions through a number of compact sensor nodes, security must be justified and ensured prior to their deployment. An adversary may compromise sensor nodes, forcing them to generate undesired data, and propagation of these data packets through the network results in wasteful energy consumption. We develop a security mechanism to detect energy-consuming useless packets, assuming that a sensor node is able to generate multiple message authentication codes (MAC) using preshared secrets. The forwarding nodes along the path verify the validity of the packet by checking the authenticity of the attached MACs. This mechanism performs well when a malicious node does not have all the cryptographic keys. However, packets, generated by the malicious node having all the keys, would be considered as legitimate, and thus, the forwarding nodes become unable to detect and discard them. To deal with this problem, we devise another mechanism in which each forwarding node is capable of checking such suspicious nodes. We have quantified the security strength through analysis and simulations to show that the proposed mechanisms make the entire network energy conserving.