Proportional Integral Derivative (PID) control is the main control method in the process of agricultural water and fertilizer regulation, and its parameter setting directly affects the control effect of water and fertilizer regulation. However, the traditional PID parameters are adjusted manually such as using the critical proportionality method, which is time-consuming and difficult to achieve optimal control effects. To solve the optimal combination of PID control parameters and improve the control effect of water and fertilizer regulation, a partial attraction adaptive firefly algorithm (PAAFA) is proposed in this paper. Specifically, a partial attraction strategy is designed to speed up the convergence of the PAAFA and reduce the oscillation problem at the late stage of the algorithm. In addition, an adaptive inertia weight operator is proposed to balance the global search capability and local search capability of PAAFA and avoid the algorithm from trapping in the local optimum. Subsequently, to test the performance of PAAFA, the algorithm is subjected to a series of simulation experiments and bench tests with the latest methods, i.e., genetic algorithm (GA), Adaptive genetic algorithm (AGA), and firefly algorithm (FA) applied to PID parameter optimization problems. The simulation results demonstrate that the regulation times of the response curve of PAAFA-based PID control are reduced by 22.75%,10.10%and 20.61%, respectively, compared with GA, AGA, and FA. The bench test results show that the PAAFA-based PID control has the smallest relative error, and best control accuracy compared to GA, AGA, and FA, with an average relative error reduction of 3.99, 2.42, and 3.50 percentage points respectively.