In this paper, a proposed efficient solution for an important power quality problem focused on harmonic distortion in the source current is introduced by using Shunt Active Power Filter (SAPF) controlled by the sinusoidal source current control strategy which is based on the instantaneous active and reactive power theory (Sinusoidal PQ-theory). As a part of this controller, there is PI-Controller which enhances the APF controller performance when tuning its proportional and integral gains. The gains of the PI-Controller are optimized in this article based on an effective metaheuristic optimization algorithm known as Mayfly Optimization Algorithm (MOA), and its effectiveness is clear when compared with other algorithms such as Particle Swarm Optimization (PSO), Artificial Hummingbird Algorithm (AHA) and Archimedes Optimization Algorithm (AOA). The performance of the optimized controller is evaluated under load variation and distorted source voltage conditions. The results obtained using MATLAB/SIMULINK prove the ability of the MOA to get the optimal PI-Controller gains which lead to enhancement of the APF controller performance to reduce the total harmonic distortion in the drawing source current with minimum and acceptable values according to (IEEE-519) harmonics standard.