The prevalent use of electronic devices in single-phase AC supplies necessitates the utilization of power factor correction (PFC) circuits at the first stage of switching power supplies. PFC circuits reduce the total harmonic distortion (THD) of the current drawn from the AC grid that is important for the efficient utilization of power lines. PFC circuits rely on an appropriate controller for prompt operation. In this paper, the optimal proportional and integral gains of a switching power supply are found based on a metaheuristic optimization algorithm. The total harmonic distortion reduction over a wide range of load is the objective of the optimization problem. The comparison of the optimal gains with the determined gains using an analytical approach demonstrates the effectiveness of the proposed approach in determination of the controller gains.