Conventional tuning of proportional–integral (PI) controllers for active power filters (APFs) cannot ensure optimal improvement of power quality performance in electric railway applications. This research introduces an artificial intelligence (AI) methodology for the design of a PI controller in electric railway systems. The adaptive Tabu search (ATS) algorithm is utilized to search for the optimal parameters of a compensating current controller and direct current (DC) bus voltage controller, with the aim of concurrently optimizing harmonic current suppression, current imbalance compensation, and power factor (PF) correction. The efficacy of the proposed method is assessed via hardware-in-the-loop (HIL) simulation. Experimental results validate that the compensating current controller and DC bus voltage controller, designed using the ATS algorithm, demonstrably improve harmonic mitigation performance. This enhancement is substantiated through the power quality index, specifically the percentage of total harmonic distortion of current (%THDi), percentage of current unbalance factor (%CUF), and the PF compliance with the IEEE standard. Consequently, the proposed approach offers a practical and effective solution for elevating power quality within electric railway systems.