The electrohydraulic servo systems (EHSS) are used extensively in industry such as flight, ships engineering, machines of injection molding, robotics, and steel and aluminum factory's equipment. It has the advantages of high power to weight ratio, linear movement, and fast response. In order to overcome the problem of nonlinearity of the controlled system, a sliding mode controller with error (ESMC) is proposed in such a way that the error signal modifies the ordinary switching mode control action. Pulse width modulation (PWM) technique is used to convert the control action into a digital signal capable of driving the solenoid of an electrohydraulic servo valve to control the oil flow entering the hydraulic cylinder so that its position could be controlled. A dynamic model of an electrohydraulic control system is simulated using MATLAB/Simulink software where the control parameters are optimized for experimental testing of PID and sliding mode controllers. The two controllers are then fine-tuned experimentally and their performance is compared under square and sinusoidal reference inputs. The experiments showed that the proposed ESMC gives less steady state error, less overshoot, and less settling time compared to both PID and ordinary switching sliding mode controllers.