An energy management system (EMS) is proposed in this paper to minimize the amount of load shedding in islanded multiāmicrogrids (MMGs) systems in a costāeffective manner. The suggested EMS adopts a twoāstage hierarchical optimization model. The first stage is called microgrid (MG) optimization, in which the load shedding in each MG is minimized. The dayāahead schedule of the diesel generator, the charging/discharging power of the battery energy storage system (BESS), the reshaped load profile after applying the demand response programs (DRP), and the shortage/surplus power in each MG are determined in the first stage of optimization. The second stage is MMG optimization, in which the amount of energy shortage in the MMG system is further minimized by energy exchange between individual MGs. The remaining shortage can be reduced with the aid of the community MG resources. The proposed optimization model is formulated as a nonlinear complex optimization problem that can be handled more efficiently by the metaāheuristic techniques compared with the conventional analytic methods. The political optimizer is used in this paper. To prove the effectiveness of this optimizer in handling the proposed model, we also solved the optimization problem using the particle swarm optimization algorithm, and results are compared.