We propose a new approach to the problem of tuning and optimizing the parameters of a PID controller based on reducing the problem to an optimization problem. In this case, the performance of the controller is evaluated by a quadratic criterion of the system output: the PID controller is tuned against the uncertainty in the initial conditions so that the system output is uniformly small; in this case, a given degree of stability of the closed-loop system is additionally guaranteed. A gradient method for finding the PID controller parameters is given. Numerous examples show that the recurrent procedure proposed is very efficient and leads to PID controllers that are quite satisfactory in terms of engineering performance indices. The article continues a series of papers by the present authors devoted to synthesizing feedback in control problems from the standpoint of optimization.