In internal combustion engines, adjusting the air-fuel ratio is essential to control the speed and minimize the burnt fuel. The throttle opening is the actuator to control the air-fuel. A better design for the used/conventional controller can give a better response without additional cost. In this work, the proposed controller gains of the proportional-integral (PI) controller are tuned to enhance the speed in constant and variable drive cycle modes. The tuning process is conducted based on two of the most efficient performance indices used in this field. The performance indices are integral absolute error (IAE) and integral time absolute error (ITAE). The optimization problem is solved using three reliable stochastic optimization algorithms to ensure mature convergence of the solutions, to avoid local optima solutions, and to ensure effective shrinking of the search space. The optimization algorithms are teaching-learning-based optimization (TLBO), particle swarm optimization (PSO), and genetic algorithm (GA). Different simulations are conducted to validate the results. The results are compared with conventional tuning methods regarding the system's time response.