The problem of obtaining a prescribed residual stress distribution in a workpiece during its thermoplastic deformation has been formulated as an optimization problem of the mechanics of deformable solids. For its solution the objective function describing the residual stress distribution has been introduced through current process parameters. An algorithm for the solution of the optimization problem, based on nonlinear programming methods, has been developed. Optimal regimes of local forced cool-down of hot rolled I-beams have been found. It is shown that, while using regulated forced cool-down, the prescribed residual stress distribution can be achieved with adequate accuracy.