Although urban train services have been introduced in various developing countries, ridership for this mode of public transport (PT) remains low. In response, urban planning authorities are seeking ways to boost passenger loyalty to these services. However, the existing literature has scarcely examined the role of physical and social environments in fostering passenger loyalty. Additionally, how loyalty is developed throughout the passenger experience - both at stations and onboard - remains unclear. Addressing this gap, the current study develops a model based on the 'service quality-satisfaction-behavioural intentions' paradigm and the Stimulus-Organism-Response (S-O-R) model to examine how the physical and social environments, both at rail stations and onboard trains, impact passenger loyalty in the context of urban train services. Additionally, this study validates the multi-dimensionality of physical environments and social environments in this context. Data collected from urban rail passengers in Hanoi, Vietnam is analyzed using Partial Least Squares Structural Equation Modeling (PLS-SEM). The findings reveal that the physical and social environments onboard trains significantly influence loyalty towards the urban train services, while the environments at stations do not have the same impact. Furthermore, both satisfaction at stations and onboard trains significantly affect the loyalty, though the influence of satisfaction with the onboard experience is much stronger than that of satisfaction with the stations. Practically, the findings assist PT authorities in evaluating existing systems and devising future PT development strategies. Also, the study informs PT providers of ways to improve passenger satisfaction and loyalty.