The paper presents a gradient-based algorithm for optimal control of nonlinear multivariable systems with control and state vectors constraints. The algorithm has a backward-in-time recurrent structure similar to the backpropagation-through-time algorithm, which is mostly used as a learning algorithm for dynamic neural networks. Other main features of the algorithm include the use of higher order Adams time-discretization schemes, numerical calculation of Jacobians, and advanced conjugate gradient methods for favorable convergence properties. The algorithm performance is illustrated on an example of off-line vehicle dynamics control optimization based on a realistic high-order vehicle model. The optimized control variables are active rear differential torque transfer and active rear steering road wheel angle, while the optimization tasks are trajectory tracking and roll minimization for a double lane change maneuver.