This study presents a comprehensive investigation into the optimization of PID control parameters for marine dual-fuel engines using an improved particle swarm algorithm. Through the development of a Matlab/Simulink simulation model, the thermodynamic behavior of the engine and the functionality of its control system are analyzed. The PID control parameters for air–fuel ratio control and mode switching control systems are fine-tuned utilizing the improved particle swarm algorithm (PSO). Simulation results demonstrate that the proposed improved PID-PSO approach outperforms traditional PID and traditional PSO-PID control methods in terms of reduced overshoot, minimized steady-state error, faster response times, and improved stability across various operating conditions and response modes. In comparison to traditional PID and PSO-PID controllers, the improved PSO-PID controller reduces the response time by 0.47 s and 0.21 s, the maximum overshoot by 98.43% and 96.05%, and decreases the absolute errors by 87.42% and 90.55%, respectively, in air–fuel ratio control using the step response method. The study's findings offer valuable insights into enhancing the performance and efficiency of marine dual-fuel engines through advanced control strategies.