Droop control is one of the main control strategies of islanded microgrid (MG), but the droop control cannot achieve reasonable power distribution of microgrid, resulting in frequency and voltage deviation from the rating value, which needs the upper control link to eliminate the deviation. However, at present, most layered control requires a centralized control center, which excessively relies on microgrid central controller (MGCC) and real-time communication among distributed generation (DG), which has certain limitations. To solve the above problems, this paper proposes a hierarchical distributed power and power quality optimization strategy based on multi-agent finite time consistency algorithm (MA-FTCA). Firstly, based on the first layer droop control, MA-FTCA is applied to introduce frequency and voltage compensation to stabilize the system frequency and voltage at the rated value. Secondly, in the third layer, the MA-FTCA is adopted to estimate the total active power and total reactive power spare capacity of the system, to realize the reasonable distribution of active power and reactive power output of each DG according to its proportion of spare capacity when the system load side changes. The control strategy proposed in this paper adopts a completely distributed control method and does not need a centralized control center in each layer of control. Finally, MATLAB/Simulink simulation platform is used to verify the correctness and effectiveness of the proposed optimization strategy.