Wireless sensor network (WSN) is an emerging important research area. The variety in and number of applications is growing in wireless sensor networks. These wireless sensor nodes are tiny devices with limited energy, memory, transmission range, and computational power. Because WSNs in general and in nature are unattended and physically reachable from the outside world, they could be vulnerable to physical attacks in the form of node capture or node destruction. These forms of attacks are hard to protect against and require intelligent prevention methods. It is necessary for WSNs to have security measures in place as to prevent an intruder from inserting compromised nodes in order to decimate or disturb the network performance. Intrusion detection in wireless sensor networks is a much needed security measure. In this thesis we present an intrusion detection framework for wireless sensor networks which does not require prior knowledge of network behavior or a learning period in order to establish this knowledge. We have taken a more practical approach and constructed this framework with small to middle-size networks in mind, like home or office networks. The proposed framework is also dynamic in nature as to cope with new and unknown attack types. This framework is intended to protect the network and ensure reliable and accurate aggregated sensor readings. Theoretical simulation results indicate that compromised nodes can be detected with high accuracy and low false alarm probability when as much as 25% compromised nodes is present in the network. Theoretical simulation results regarding data aggregation indicates that compromised nodes will be limited in their influence on the aggregated data even with as much as 40% compromised nodes in the network. We have only simulated the framework theoretically in a mathematics program and evaluated the theoretical properties of the algorithms. The results are promising and the framework should be simulated in a network simulator for further evaluation.