The invention relates to a system and a method for rail train collision prevention based on a wireless sensor network. The system is provided with a train head device, a train tail device and a rail side device, wherein the rail side device comprises a wireless sensor network, the wireless sensor network consists of communication base stations and network nodes, a rail line is divided into a plurality of equidistant closing areas, the middle point position in each closing area is provided with one communication base station, both sides of each communication base station are respectively provided with the network nodes in equidistant way, each communication base station is provided with a wireless communication module, GSM-R (global system of for mobile communications for railway) wireless equipment, a power supply module and a rail detector, each network node comprises a wireless communication module, a power supply module and a rail detector, the train head device comprises a main controller, a wireless communication module, a power supply module and a braking module, the train tail device comprises a wireless communication module and a power supply module, the output of the power supply module is connected with the wireless communication module, and the train head device and the train tail device are used as movable nodes and are added into the wireless sensor network of the rail side device.