The development of applications for wireless sensor networks (WSNs) have grown significantly in recent years. Currently, WSNs are an interesting technological alternative to develop applications that constantly need to monitor the state of any variable in the scope of different types of scenarios. If the applications detect changes in the values of these variables, they can trigger preventive actions that allow restoring the normal conditions in the monitored environment. Some examples of applications that can benefit from the use of WSNs are event detection applications, among which we have the detection of forest fires. This kind of applications has recently received much attention since, every year, forest fires devastate large areas, damaging flora and fauna, and causing huge material and human losses. Another area of great interest is the detection of gas propagation. The main goal of these applications is to avoid tragedies, especially when dangerous gases are involved. On the other hand, WSNs have also been used in the detection and tracking of targets and intruders. These applications are useful in the surveillance and security of restricted areas where the service offered or the objects therein contained have great value. As we can observe, all these types of events can be classified as critical events since the system's response time is of great importance. To efficiently implement applications that rely on wireless sensor networks for detecting the spreading of fire and gas, as well as for the detection and tracking of intruders, it is convenient the use mechanisms that allow the detection and reporting of critical events to be correct and to be made within a short period, so that the system can inform and act immediately to avoid more serious problems. In this doctoral thesis, an architecture for wireless sensor networks is proposed, that allows the system to do real time detection of events that alter the normal state of the sensed environment, acting in consequence afterwards. The proposed architecture uses IEEE 802.15.4 technology, and two new routing protocols are proposed, which aim to optimize the delivery of information throughout the network. Data aggregation algorithms are also proposed, thereby allowing to reconstruct the monitored events. The first proposed protocol is the Drain Announcement Based Routing (DABR), which uses a route discovery algorithm where the drain announces its location to all sensor nodes that integrate the WSN. This routing protocol aims at reducing the route discovery overhead by sensor nodes attempting to send reports to the drain node. The proposed algorithm also aims at reducing the end-to-end delay by introducing low routing overhead on the communication channels. This protocol assumes that both the sensor and the drain nodes are fixed (that is, with no mobility), and that the sensor nodes are deployed using a grid topology. The second proposed routing protocol is the Mobile-sink Routing for Large Grids (MRLG), which is intended to reduce the routing control traffic in scenarios where the drain is mobile. The sensor nodes should update their route towards the drain, with the restriction that only those nodes near the drain and affected by its mobility need to update their routing table, thereby avoiding modifying routing tables for those nodes that are far-away. In this work, new data aggregation algorithms are also proposed, being used to determine the affected area in the case of gas and fire spreading, as well as locating intruders dynamically and in real time. These algorithms identify areas at risk, executing the necessary actions to guarantee the security of the sensed area. Finally, as part of the tools developed and implemented to cover all aspects of the modeling process, a platform has been developed that allows generating and evaluating both internal and external fire or gas spreading events, as well as intruder mobility patterns. As a methodological tool we used the ns-2 simulator, which allows evaluating the proposed protocols under the IEEE 802.15.4 standard, analyzing the impact that different design parameters have on their performance.