A new approach for the numerical solution of the optimal control problem is presented. This approach is based on the parametrization of the control function and computation of the first and the second derivatives of the cost functional over parameters. Computation of the second derivatives is carried out using an integral representation for the second variation of the trajectory of a controlled dynamical system,which is obtained in this work and includes a tensor of the third rank. The proposed approach differs from the approach being used previously, in which the second derivatives of the cost functional are expressed through the matrix momenta. A numerical method based on the second variation of the trajectory can be effective in problems with a great number of parameters. Using the matrix momenta, one should integrate a system of differential equations, the number of which is quadratic in the number of parameters. In the present approach, the number of the equation to be integrated is determined only by the dimension of the phase space and can be sufficiently smaller.