A scheme to implement the controlled-NOT (CNOT) gate for quantum systems is proposed, which is based on Lyapunov control. The scheme does not require precise control of the interaction time since the system is stable when the control fields vanish. In particular, the control fields can be easily obtained by most initial states. As an example, the CNOT gate is realized for two atoms trapped in an optical cavity by exploiting two disturbance cases. Compared to continuous disturbance, the fidelity of the CNOT gate is higher under impulsive disturbance, however, interaction times are much longer. Numerical simulations indicate that the scheme is robust against variations of control parameters and decoherence caused by atomic spontaneous emission and cavity decay. Therefore, the scheme may provide useful applications in quantum computation.