A robust, optimized power system stabilizer (PSS) is crucial for oscillation damping, and thus improving electrical network stability. Additionally, real-time testing methods are required to significantly reduce the likelihood of software failure in a real-world setting at the user location. This paper presents an Antlion-based proportional integral derivative (PID) PSS to improve power system stability during real-time constraints. The Antlion optimization (ALO) is developed with real-time testing methodology, using hardware-in-the-loop (HIL) that can communicate multiple digital control schemes with real-time signals. The dynamic power system model runs on the dSPACE DS1104, and the proposed PSS runs on the field programmable gate arrays (FPGA) (NI SbRIO-9636 board). The optimized PSS performance was compared with a modified particle swarm optimization (MPSO)-based PID-PSS, through different performance indices. The test cases include other step load perturbations and several short circuit faults at various locations. Twelve different test cases have been applied, through real-time constraints, to prove the robustness of the proposed PSS. These include 5 and 10% step changes through 3 different operating conditions and single, double, and triple lines to ground short circuits through 3 different operating conditions, and at various locations of the system transmission lines. The analysis demonstrates the effectiveness of ALO and MPSO in regaining the system’s stability under the three loading conditions. The integral square of the error (ISE), integral absolute of the error (IAE), integral time square of the error (ITSE), and integral time absolute of the error (ITAE) are used as performance indices in the analysis stage. The simulation results demonstrate the effectiveness of the proposed PSS, based on the ALO algorithm. It provides a robust performance, compared to the traditional PSS. Regarding the applied indices, the proposed PSS, based on the ALO algorithm, obtains significant improvement percentages in ISE, IAE, ITSE, and ITAE with 30.919%, 23.295%, 51.073%, and 53.624%, respectively.