The operation of active power filters (APFs) under nonideal grid conditions, such as grid-frequency fluctuation and voltage harmonics, can lead to significant degradation in harmonic compensation performance. This paper proposes an adaptive digital-control scheme for a three-phase APF for use in harmonically distorted and variable-frequency grid conditions. This scheme is comprised of a grid-frequency adaptive resonant current controller and an enhanced synchronous-reference-frame phase-locked loop (SRF-PLL). The PLL uses an inherently stable adaptive-filtering stage to improve grid phase and frequency estimates in the presence of voltage harmonics. The improved PLL frequency estimate is used to update the resonant gains of a PI + vector-proportional-integral current-control scheme, implemented in the SRF. This enables the APF to maintain optimal performance in distorted grid conditions. The performance of the proposed APF control scheme is evaluated in a test microgrid, with a 15-kVA three-phase voltage-source converter configured as the APF, a 90-kVA grid emulator utilized to replicate distorted grid conditions, and a load emulator implemented to draw harmonic currents. The control scheme presented here is shown to demonstrate significant performance improvements under nonideal grid conditions compared with equivalent adaptive and nonadaptive methods.