This paper investigates transient stability enhancement of both Single Machine Infinite Bus (SMIB) and multi-machine systems using a Unified Power Flow Controller (UPFC) tuned by Particle Swarm Optimization (PSO). It details the UPFC's ability to inject variable voltage and manage real and reactive power flow, thereby mitigating power oscillations during transient conditions. The study includes mathematical modeling and simulation results demonstrating the effectiveness of the UPFC in improving system stability under various operating conditions.