A new probabilistic safety assessment method applicable to conventional and high speed railway lines is presented. The main idea consists of reproducing the railway line items which are relevant to safety by means of a Bayesian network as an alternative to more limited event and fault tree structures. The model evaluates the probability of incidents associated with the circulation of trains along the lines with special consideration of human errors. To this end, all the line relevant elements, such as light and speed limit signals, rolling stock failures, falling materials, slope slides in cuttings and embankments, tunnel or viaduct entries or exits, automatic train protection systems and other elements are reproduced with a special consideration of human behavior and human error. Since driver's attention plays a crucial role, its evolution and changes with driving time and due to other factors, such as seeing light signals or receiving acoustic signals are taken into account. The model updates the driver attention level and evaluates the probability of accident associated with the different elements encountered along the line. A continuously increasing risk graph with continuous and sudden changes is obtained indicating where actions must be taken to improve safety. This avoids waste of time and money by concentrating on the items most critical to safety. Finally, some illustrative examples are used to point out the models relevance.