This paper proposes an improved hierarchical control strategy consists of a primary and a secondary layer for a three-phase 4-wire microgrid under unbalanced and nonlinear load conditions. The primary layer is comprised of a multi-loop control strategy to provide balanced output voltages, a harmonic compensator to reduce the total harmonic distortion (THD), and a droop-based scheme to achieve an accurate power sharing. At the secondary control layer, a reactive power compensator and a frequency restoration loop are designed to improve the accuracy of reactive power sharing and to restore the frequency deviation, respectively. Simulation studies and practical performance are carried out using the DIgSILENT Power Factory software and laboratory testing, to verify the effectiveness of the control strategy in both islanded and grid-connected mode. Zero reactive power sharing error and zero frequency steady-state error have given this control strategy an edge over the conventional control scheme. Furthermore, the proposed scheme presented outstanding voltage control performance, such as fast transient response and low voltage THD. The superiority of the proposed control strategy over the conventional filter-based control scheme is confirmed by the 2 line cycles decrease in the transient response. Additionally, the voltage THDs in islanded mode are reduced from above 5.1% to lower than 2.7% with the proposed control strategy under nonlinear load conditions. The current THD is also reduced from above 21% to lower than 2.4% in the connection point of the microgrid with the offered control scheme in the grid-connected mode.