Inductance–capacitance–inductance (LCL) filters are very attractive candidates for renewable energy system applications due to their high efficiency, high harmonic reduction, small bulk, and improved harmonic distortion (THD). These papers take advantage of the capabilities of renewable energy sources and inject them into the network by using an inverter when it enters work at high loads at certain times. Therefore, it is necessary to control power with certain controllers. The proportional-integral controller (PI) is used; conventional methods for tuning the controller parameters cannot give satisfactory performance due to the high instability of the closed-loop system. This paper presents the particle swarm optimization (PSO) method for tuning the controller's parameters to achieve optimum performance associated with sufficient stability margin. The mathematical models for the LCL filter and the frequency response were investigated by using the bode-plot. The proposed approach shows effective results for both power control and harmonic reduction. The proposed PI-PSO controller gives overshoot (1.08%), settling time (0.03 sec), rise time (0.00035 sec) and improved THD from 10.29% to 1.67% with compared to using the trial and error method, which gives (1.035%), (0.015) and (0.003) and THD from 10.23% to 1.575%, respectively.