Abstract In view of the crucial importance of optimal control in many application areas and the improved performance of path-fitted variational integrators, the paper links these two aspects and presents a methodology to find optimal control policies for mechanical systems. The main process of the methodology is employing path-fitted variational integrators to discretize the forced mechanical equations and further take the obtained discrete equations as equality constraints for the final optimization problem. Simultaneously, the discretization also provides a reasonable way to approximate the objective function and incorporate the boundary conditions. With the transformation of optimal control problems into nonlinear optimization problems, all the benefits of path-fitted variational integrators are inherited by the presented methodology, mainly expressed in giving more faithful optimizations and thus more accurate solutions, providing a greater possibility of global optimality, as well as conserving computed control efforts. These superiorities, verified by the optimal control of an overhead crane, indicate that the methodology has high potential application in industrial control field.