This paper presents the modelling and simulation of a three-phase shunt active power filter (SAPF) using the direct power control (DPC) based on the Particle Swarm Optimization (PSO) algorithm for power quality improvement. In the DPC technique, the switches states of the inverter are selected from a table of switching based on the immediate errors between the active and reactive powers and their reference values. PSO algorithm is used in order to optimize the PI controller gains of the DC link voltage. This PI-PSO gives better results for robustness, harmonic minimization and reduces the overshoot and undershoot of PI controller. A MATLAB/SIMILINK simulation is provided to demonstrate the performance of the proposed approach.