The outbreak of the COVID-19 pandemic seriously affected railway businesses. The motivation of this study is to provide vital information to railway company management and policymakers by quantitatively assessing the cost efficiency of railway operations. We examine the efficiency of Japanese listed railway companies by applying stochastic frontier analysis to their operational and financial data from 2005 to 2020. Then, we classify the companies into four groups by cost efficiency levels and identify the characteristics of the best-practice companies. Furthermore, we analyze the factors influencing cost efficiency before and during the pandemic. Finally, we discuss the sustainable business practices and measures of digital transformation (DX) that can be applied to improve efficiency and survive severe events like the pandemic. From the results, we reveal that cost-efficient companies succeeded in securing profits through the creation of new services by proactive DX investments. The practical contributions of this study are threefold: quantifying the deterioration in efficiency due to the pandemic; identifying characteristics of best-practice companies; and examining the relationship between cost efficiency levels and concrete measures and investments for sustainable business practices. This study proposes a new analytical framework that combines conventional methods.