Sustainable railway construction and operation are threatened by densely occurring geological hazards in complex mountainous regions. Thus, during the alignment optimization process, it is vital to reduce the harmful impacts of geological hazards to a railway. However, current alignment-related studies solely consider such threats in existing geological hazard regions and, outside these regions, slight attention has been devoted to the assessment of potential hazardous impacts along the alignment. To this end, this paper proposes a novel railway alignment optimization model considering both existing and potential geological hazards based on quantitative geological hazard evaluation criteria from a sustainable safety perspective. More specifically, a geohazard zone classification method, within which an energy–slope model is integrated, is first developed. Three geohazard regions, namely the geohazard outbreak region, buffer region and fuzzy region, can then be obtained. Afterward, a spatial geological hazard assessment model is constructed considering the geological danger of three kinds of geohazards (debris flows, landslides and rockfalls) and railway construction vulnerability. This model is incorporated into a previous cost–hazard bi-objective alignment optimization model. Finally, the effectiveness of the proposed model is verified by applying it to a real-life case of the Sichuan–Tibet railway. The results show that this method can effectively optimize mountain railway alignments by concurrently reducing geological hazards and costs, which is beneficial to railway safety and sustainable construction and operation.