This paper proposes a control architecture of distributed generators (DGs) inverters and shunt active power filters (APFs) in microgrids to compensate voltage harmonics in a coordinated way. For this, a hierarchical control structure is proposed that includes two control levels. The primary (local) control consists of power controllers, selective virtual impedance loops and proportional-resonant (PR) voltage/current controllers. The secondary (central) control manages the compensation level 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/or overloading of the inverters. After occurrence of each case, active power filter (APF) participates in harmonic compensation and consequently the compensation efforts of DGs decrease to avoid excessive harmonics or overloading of interface inverters. Effectiveness of the proposed control scheme is demonstrated through simulation studies.