This paper presents a methodology on the design of an optimal predictive control scheme applied to an islanded microgrid. The controller manages the batteries energy and performs a centralized load shedding strategy to balance the load and generation within the microgrid, and to keep the stability of the voltage magnitude. A nonlinear model predictive control (NMPC) algorithm is used for processing a data set composed of the batteries state of charge, the distributed energy resources (DERs) active power generation, and the forecasted load. The NMPC identifies upcoming active power unbalances and initiates automated load shedding over noncritical loads. The control strategy is tested in a medium voltage distribution system with DERs. This control strategy is assisted by a distribution monitoring system, which performs real-time monitoring of the active power generated by the DERs and the current load demand at each node of the microgrid. Significant performance improvement is achieved with the use of this control strategy over tested cases without its use. The balance between the power generated by the DERs and the load demand is maintained, while the voltage magnitude is kept within the maximum variation margin of pm 5\% recommended by the standard ANSI C84.1-1989.