The proportional-integral-derivative (PID) controller is widely used in motion control systems due to its simplicity and effectiveness. To achieve satisfactory performance, the PID parameters must be properly tuned. Although numerous PID tuning methods were investigated in the past, most of them were based on either time-domain or frequency-domain responses, while integration of features in both domains for PID tuning was less addressed. However, many industrial practitioners still found it difficult to compromise multiple conflicting control objectives, such as fast responses, small overshoot and tracking errors, and good robustness, with PID controllers. Moreover, it is desirable to adjust PID parameters online such that plant variations and unexpected disturbances can be compensated for more efficiently. In view of these requirements, this paper proposes an adaptive PID control law that updates its parameters online by minimizing the time-domain tracking errors subject to frequency-domain constraints that are imposed for loop shaping. By combining optimization criteria in both time and frequency domains for online parameter adjustment, the proposed PID controller can achieve good tracking performance with adequate robustness margin. Then the proposed PID law is applied to control an XZ-table driven by AC servo motors. Experimental results show that the tracking performance of the proposed controller is superior to that of a constant-gain PID controller whose parameters were tuned by the commercial Matlab/Simulink PID tuner.