This article focuses on solving a finite-horizon nonlinear optimal control problem by using the Pontryagin's maximum principle. In practical applications, linearization is a common approach for solving nonlinear dynamical systems. However, it is not universally applicable due to various reasons, such as instability and low accuracy. In contrast to linearization, the inherent challenge in directly solving the above nonlinear optimal control problem lies in addressing the highly coupled nonlinear forward and backward differential equations. In order to address this problem, an equivalent relationship is established between these equations and a new optimization problem. By exploiting the inherent relationship between supervised learning and an optimization problem from the view of a dynamical system, a deep neural network framework is constructed for describing the new optimization problem. Furthermore, a numerical algorithm for optimal control, which is very powerful for a large variety of nonlinear dynamical systems, is implemented by training a deep residual network. Finally, the effectiveness of the algorithm is demonstrated by solving a trajectory tracking control problem for automatic guided vehicle. The obtained results reveal that the proposed control scheme can achieve high-precision tracking.