This study investigates the control and dynamic operation of the Unified Power Flow Controller made of shunt and series converters, a Static Synchronous Compensator, and a Static Synchronous Series Compensator, respectively, connected back-to-back through a common DC-link capacitor. The model of a 48-pulse Voltage Source Converter is constructed from a three-level Neutral Point Clamped converter, which allows the total harmonic distortion to be reduced. An optimal conduction angle tracking system of the three-level inverter is designed to minimize distortion by detecting proper harmonic component elimination. Starting from the six-step modulation strategy, the dq decoupled control schemes of both compensators in open and closed loops are presented. Finally, the MATLAB-Simulink model of the power flow controller is implemented and analyzed. The results show that the controller can track the power changes and apply a suitable voltage to the power system so that the power flow can be controlled. This way, the power flow controller dynamically improves the voltage and power quality across the power network while simultaneously improving the transient stability of the system. It can eliminate all system disturbances resulting from oscillations and harmonics in voltage and current within a very short time. The procedural approach used to model and simulate the Unified Power Flow Controller, as well as the new algorithm used to obtain the harmonic number that minimizes the total harmonic distortion, can be applied to any AC power system.