Abstract-Microgrids (MGs) have been receiving more and more attention, as it can environmentally and reliably integrate intermittent renewable energy sources (RES). Conventionally, an islanded MG is controlled and optimized in a hierarchical strategy, i.e., primary droop control, second automatic generation control (AGC), and tertiary economic dispatch (ED). ED has large time-scale while AGC has small time-scale. Thus the gap between ED and AGC may decrease the economic efficiency of a MG. In this paper, a distributed optimal automatic generation control (OAGC) algorithm is proposed to integrate the gap between ED and AGC, i.e., the MG can realize AGC and ED at the same time. In order to implement the OAGC algorithm, each DG is assigned with an agent and the agents only require the local measurements and communicate with its neighbors. The proposed OAGC algorithm is fully distributed, which involves low costs related to modify the architecture of a MG and robust against single point failure. Simulation results demonstrate the effectiveness of the proposed algorithm.Index Terms--distributed algorithm, droop control, Microgrid, multi-agent system (MAS), optimal automatic generation control (OAGC).