Differential absorption lidar (DIAL) is widely used to monitor spatial and temporal variations in the distribution of atmospheric gases, such as CO2 and O3. Single-photon detectors are critical components of DIAL systems, and their after pulse effect can distort echo signals, significantly compromising the accuracy of gas concentration inversion. This study introduces an intelligent optimized after pulse correction algorithm that utilizes differences in signal response between two detectors. The algorithm evaluates the after pulse characteristics of the detectors and applies real-time corrections during signal processing. This effectively mitigates the interference caused by strong after pulse effects on signal integrity. Comparative experiments with real lidar signals demonstrate that this algorithm substantially enhances the detection performance of DIAL systems. Notably, the proposed method enables online evaluation and calibration of the after pulse effect using lidar signals. Unlike traditional calibration approaches that rely on pre-installation detector testing, this technique provides a more thorough evaluation and effectively addresses the worsening of after pulse effects due to aging lidar system components. The results show that this method increases the maximum nighttime detection range of the differential absorption lidar from 1500 m to 2000 m.