A control system for controlling an electrical power microgrid including loads and distributed energy resources, the control system comprising: a component control layer including component control devices connected directly to the loads and distributed energy resources; a middle level control layer including aggregating control devices, each aggregating control device being connected to a respective plurality of the component control devices; a microgrid control layer including one or more microgrid control devices connected to the aggregating control devices and further comprising a contingency metric computation module for computing a contingency metric indicating a level of operational threat based on characteristics of the electrical power microgrid and its environment; wherein in a first contingency level indicating substantially no operational threat, the microgrid is in grid connected mode, the control system maintains high real time reserve margin and the control system is configured to operate in a centralized mode wherein instructions and set points for the loads and distributed energy resources are transmitted from the microgrid control layer to the middle level control layer and the component control layer; in a second contingency level indicating an intermediate operational threat, the microgrid is mostly in island mode, the control system maintains low real time reserve margin and the control system is configured to operate in a partially centralized mode wherein at least some instructions and set points for the loads and distributed energy resources are originating from the aggregating control devices and wherein the microgrid control layer moves toward strictly monitoring and tracking the current and future system state; in a third contingency level indicating a high operational threat, the microgrid is in island mode, the control system maintains minimum real time reserve margin, the control system is configured to operate in a partially centralized mode wherein instructions and set points for the loads and distributed energy resources are originated by the aggregating control devices, the microgrid controller is in monitoring-only mode and undertakes pre-computation of control actions for load shedding, neighbouring middle level controllers communicate with each other via the microgrid controller if required and if possible and a system backup storage is in use; in a fourth contingency level indicating a very high operational threat, the microgrid is in island mode, the control system maintains no real time reserve margin, the control system is configured to operate in a decentralized mode wherein the component control layer is operated without receiving instructions and set points from the middle level control layer or the microgrid control layer, the microgrid controller and the middle layer controllers are in monitoring-only mode, the component control devices in the component control layer are placed in droop mode, automatic load shedding is implemented to keep serving at least the highest priority loads and all reserves and storage are in use. a component control layer including component control devices connected directly to the loads and distributed energy resources; a middle level control layer including aggregating control devices, each aggregating control device being connected to a respective plurality of the component control devices; a microgrid control layer including one or more microgrid control devices connected to the aggregating control devices and further comprising a contingency metric computation module for computing a contingency metric indicating a level of operational threat based on characteristics of the electrical power microgrid and its environment; wherein