Abstract In this work, we present a numerical approach based on the shifted Legendre polynomials for solving a class of fractional optimal control problems. The derivative is described in the Atangana–Baleanu derivative sense. To solve the problem, operational matrices of AB-fractional integration and multiplication, together with the Lagrange multiplier method for the constrained extremum, are considered. The method reduces the main problem to a system of nonlinear algebraic equations. In this framework by solving the obtained system, the approximate solution is calculated. An error estimate of the numerical solution is also proved for the approximate solution obtained by the proposed method. Finally, some illustrative examples are presented to demonstrate the accuracy and validity of the proposed scheme.