This paper uses a particle swarm optimization (PSO) algorithm, an adaptive weighted PSO (AWPSO) algorithm, and a genetic algorithm (GA) to determine the optimal proportional-integral-derivative controller's parameters of a hydraulic position control system. A typical hydraulic servo system has been selected as an application. The mathematical model of this hydraulic servo system which comprises the most relevant dynamics and nonlinear effects is considered. The model simulates the behavior of a REXROTH servo valve and includes the nonlinearities of friction forces, valve dynamics, oil compressibility, and load influence. The performance indices, which have been used in the optimization process, are integral absolute error, integral square error and integral time absolute error. The proposed controller is implemented on the simulation model to identify the best method for tuning the controller. Compared with GA and AWPSO results, the PSO method has been found to be more efficient and robust in improving the step response of a position control for hydraulic systems in terms of settling time, maximum overshoot and undershoot.