With the increasing integration of renewable energies into power grids, their control and power quality are becoming the main focus of many research efforts. In a grid-connected photovoltaic system, the control strategy is necessary to efficiently use the solar energy as well as to ensure high power quality. This paper presents a study on the robustness of a Fractional Order PI controller based on the Particle Swarm Optimization algorithm (PSO-FOPI) in a grid-connected PV system. The controller used was integrated into the inverter to apply voltage-oriented control (VOC). Fractional order controllers have an additional degree of freedom, so that a wider range of parameters is available to provide better control. Parameter optimization of the FOPI and classical PI controllers are performed using the PSO algorithm. The performance of the FOPI controller is compared with that of the classical PI controller. A complete study of the behavior of the grid connected PV system is tested using MATLAB/Simulink. The simulation results show the performance and efficiency of the PSO-FOPI controller compared to the classical PI controller in terms of rapidity, stability and precision, as well as the THD reduction of the current injected to the grid for any variation of solar irradiance.