This paper presents a novel method to optimally place the Distribution Static Synchronous Compensator (D-STATCOM) in a distribution system using the firefly algorithm (FA) for enhancing power quality. In the proposed method, the average voltage total harmonic distortion (THD V ), average voltage deviation and total investment cost are considered as the objective functions, where voltage and power limits for individual buses are chosen as the optimization constraints. The performance of the proposed FA is investigated using the Matlab software on the radial IEEE 16bus test system. The obtained results are also compared with the particle swarm optimization and genetic algorithm. The simulation results verify the ability of FA in accurately determining the optimal location and size of the D-STATCOM in radial distribution systems.Index Terms-D-STATCOM, optimal placement, firefly algorithm, voltage sag