This paper presents an energy management system (EMS) for a stand-alone droop-controlled microgrid, which adjusts generators output power to minimize fuel consumption and also ensures stable operation. It has previously been shown that frequency-droop gains have a significant effect on stability in such microgrids. Relationship between these parameters and stability margins are therefore identified, using qualitative analysis and small-signal techniques. This allows them to be selected to ensure stability. Optimized generator outputs are then implemented in real-time by the EMS, through adjustments to droop characteristics within this constraint. Experimental results from a laboratory-sized microgrid confirm the EMS function.