This paper presents a new harmonic compensation system using filter compensator devices in a hybrid micro‐grid (MG). In order to reduce the amplitude of current and voltage harmonics, two separate systems, including a switched power filter compensator (SPFC) and a switched active power filter (SAPF) have been used in the AC side of the MG. The gain coefficients of both SAPF and SPFC modules (with different controllers) using meta‐heuristic algorithms are optimized and applied for three harmonic loops of voltage, current and controller error to obtain an optimal response for reducing the harmonic amplitude of current and voltage. The objective function, containing controller error, current and voltage harmonics is defined and followed by the optimized coefficients for the PID controller of each of the SAPF and SPFC modules. To find the best answer to this problem, the related gains using four meta‐heuristic algorithms, including artificial bee colony (ABC), particle swarm optimization (PSO), harmonic search (HS), and differential evolution (DE) are optimized and compared. The simulation results show that using the proposed method, the total harmonic distortion of the system can be significantly reduced.