These days, because power quality (PQ) issues are costing industrial customers a lot of money, both electrical utilities and end-users are paying a lot of attention to them. The most significant and frequent PQ concerns for sensitive loads are voltage sag and swell. This manuscript proposes an optimization technique for enhancing the control system of a unified power quality conditioner (UPQC) connected solar photovoltaic system in the distributed generation system. The proposed strategy is the archerfish hunting optimizer (AHO). The objective of the AHO approach is to optimizing UPQC operation in distribution systems, focusing on targeted power quality enhancement. The optimal control pulses are produced by the series active power filter and the shunt active power filter, depending on the load-side and source circumstances. During the load variation states the AHO technique manages the power loss, total harmonic distortion (THD), and voltage instability issue respectively. The performance of the AHO methodology is carried out on the MATLAB platform and compared with existing methods, like particle swarm optimization (PSO), latent semantic analysis (LSA), and ant-lion optimizer (ALO). The existing methods THD are 6.35%, 7.85%, and 9.19%. The proposed method of THD is 4.22%. From the outcome, it concluded that the proposed method based on the THD is low contracted to present techniques.