This paper addresses the coordinated control of distributed generators (DGs) inverters and active power filters (APFs) to compensate voltage harmonics in microgrids. For this, a hierarchical control system is proposed to mitigate voltage harmonic distortion. The hierarchical control structure includes two control levels: primary control and secondary control. Primary control consists of power controllers, selective virtual impedance loops and proportional-resonant (PR) voltage/current controllers. Secondary control manages the compensation of voltage harmonic distortion of sensitive load bus (SLB). Compensation of SLB harmonics by control of DGs may cause excessive voltage harmonics at the terminal of one or more of DGs interface inverters and/oroverloading of the inverters. After occurrence of each of these cases, active power filter (APF) participates in harmonic compensation and consequently the compensation efforts of DGs decrease to avoidexcessive harmonics or loading of DGs' inverters. Effectiveness of the proposed control scheme is demonstratedthrough simulation studies.