This paper presents a nonlinear control strategy for a single-phase Unified Power Flow Controller (UPFC) aimed at improving energy quality in perturbed power grids supplying nonlinear loads. The proposed controller, which includes three control loops designed via Lyapunov and backstepping techniques, addresses current harmonics, reactive power compensation, and voltage regulation without neglecting grid impedance. Simulations demonstrate the effectiveness and robustness of the controller in achieving specified power quality objectives.