In wireless sensor networks (WSN), message security is an important concern. The protection of integrity and confidentiality of information and the protection from unauthorized access are important issues. However, due to factors such as resource limitations, absence of centralized access points, open wireless medium and small size of the sensor nodes, the implementation of security in WSN is a challenging task. In this paper, we propose a protocol, quality-based distance vector routing (QDV), for securing WSN using concepts based on Ant colony optimization ACO [1]. Two fundamental parameters-quality-of-service (QoS) and reputation [2]-are used. The high value of reputation of a node signifies that the node is trusted and is more reliable for data communication purposes. As a node shows signs of misbehavior, its reputation decreases, which, in turn, affects its quality-of-security QSec [2], thereby disabling the malicious nodes from gaining access to the network. By incorporating these two factors, we are able to distinguish the nodes present in the network. We, then, present a method to achieve "equilibrium" where the node is able to guarantee that its neighbors are secure. Copyright (C) 2008 John Wiley & Sons, Ltd.