Recently, technological advances in the design of processors, memory and radio communications have propelled an active interest in the area of distributed sensor networking, in which a number of independent, self-sustainable nodes collaborate to perform information gathering and processing in real time. Networks of such devices are commonly referred to as Wireless Sensor Networks (WSNs),which are envisioned as a bridge between the modern broadband packet data networks and the physical world. WSNs have made possible real-time data aggregation and analysis on an unprecedented scale. Naturally, they have attracted attention and garnered widespread appeal towards applications in diverse areas including disaster warning systems, environment monitoring, health care, safety and strategic areas such as defence reconnaissance, surveillance, and intruder detection. Due to the distributed nature, multi-hope communications and their deployment in remote areas, WSNs are vulnerable to numerous security threats that can adversely affect performance. Therefore, to ensure the functionality of WSNs, security is the first and foremost concern in almost all wireless sensor networking scenarios. WSN mechanisms cannot at present ensure that an attack will not be launched. For example, using a compromised node an adversary could perform an attack acting as a legitimate node of the network to acquire all the information. Such attacks are known as internal attacks. Therefore, it is important to protect the wireless sensor network from internal attacks, which is the purpose of this thesis. This thesis investigates internal security issues in wireless sensor networks (WSNs) and proposes relevant solutions. The development of multi stage mechanisms to protect WSNs from internal attacks is performed. The major contributions of this thesis to prevent internal attacks are summarised below. Initially, this thesis developed misbehaviour identification mechanisms with multi agents through timing control, the pairwise key method and cosine similarity based on the abnormal behaviour identification method (ABIM). It is a fast, robust mechanism, and also gives good results when data sets are distinct or well separated from each other. Secondly, this research investigated and took the advantage of the Dempster- Shafer theory (DST) to develop a novel algorithm for protecting WSNs from internal attacks. This algorithm observes neighbour nodes in a WSN and uses parameters to make judgments for the behaviour based on the DST. The DST considers the observed data as a hypothesis. If there is uncertainty about which hypothesis the data fits best, the DST makes it possible to model several single pieces of evidence within the relations of multi hypotheses. Using this method the system does not need any prior knowledge of the pre-classified training data of the nodes in a WSN. Thirdly, this work extended the algorithm of the Markov Chain Monte Carlo (MCMC) – Metropolis-Hasting (MH) to our research to detect internal attacks on WSNs. With the MCMC method, it is possible to generate samples from an arbitrary posterior density and to use these samples to approximate expectations of quantities of interest. Moreover, it works in real time by constricting the sample chain and computes the changes together with an acceptance ratio. The new algorithm can decide the internal attacker based on the acceptance ratio. This work used the fourth generation programming language MATLAB and Java based development J-Sim for simulations. The simulation results show that the algorithm for the detection of the internal attacks is effective. In a simulation, the accuracy of detection in one hop communication, in the three stages, is between 75% and 95% based on the percentage of the compromised node. The accuracy of detection is higher for compromised nodes less than 10% even though the system does not survive if the compromised node is more than 50%.