This paper describes a control algorithm based on modified enhanced phase-locked loop (MEPLL) in dynamic voltage restorer (DVR). It compensates distortions and unbalances in the supply voltage along with voltage sag/swell. Three-phase MEPLL extracts the fundamental positive-, negative-, and zero-sequence components from the distorted/unbalanced signals. Further fundamental positive-sequence components are used in the reference load voltage calculations. In addition to track the angle of the input signals similar to the conventional PLLs, the proposed algorithm (MEPLL) offers features of getting fundamental and sequential components in case of distorted or unbalanced grid voltage for all the three phases simultaneously. Optimization approach named as autonomous groups particle swarm optimization, a variant of PSO is used for the calculation of PI-controller gains. The integrated time square error is used as a cost function for optimization of an error between the reference and actual values. This approach of tuning PI gains improves the performance by eliminating the manual process. The proposed control algorithm is implemented in DVR system using MATLAB software and validated in a laboratory environment. The performance shows that the proposed control algorithm gives time effective and satisfactory solution for the unpredictable issues mentioned.