The optimization of the train traction energy consumption in urban rail transit is a nonlinear optimization problem, and its solution is a very difficult task. This article focuses on the optimization of train traction energy consumption on the line with multiple stations. First, a single-objective nonlinear energy-saving optimization model is established for a given line and total travel time. Second, a two-stage optimization algorithm is proposed to solve this model. In the first stage, for a given interval and travel time, an optimization model of the traction energy consumption is established by using the distance discretization method. A dichotomous iterative algorithm based on energy consumption is proposed to search the optimal traction energy consumption. By calling this algorithm repeatedly, the energy–time curve of each interval can be obtained. In the second stage, according to these energy–time curves, the total travel time of a train on the line is allocated to each interval one by one in the form of time slices. And finally the optimal travel time and optimal traction energy consumption of the train on each interval are obtained. This method does not need to set the train operation mode sequence in advance but adaptively selects the energy-saving operation mode according to the line constraints and the train parameters. The up-direction from Yizhuang to Tongjinan of the Beijing Metro Yizhuang line in China is selected as the test section. The experimental results demonstrate the effectiveness and computational efficiency of our proposed methods and algorithms. Moreover, the dichotomous iterative algorithm runs so fast that it can be used in real-time driver advisory systems or automatic train operation systems.