Microgrids are subsystems of the distribution grid operating as a single controllable system either connected or isolated from the grid. In this study, a novel cooperative model predictive control (MPC) framework is proposed for networks of microgrids sharing a distributed energy resource (DER). The operation of the microgrids, along with the shared DER, are coordinated to the benefit of the Distribution System Operator (DSO) such that a common goal is achieved, e.g., minimizing energy exchanged with the distribution grid and the overall energy costs. Each microgrid is equipped with an MPC-based Energy Management System (EMS), responsible for optimally controlling flexible loads, heating systems and local generation devices based on end-user preferences, weather-dependent generation and demand forecasts, energy prices, technical and operational constraints. The proposed coordination algorithm is distributed and guarantees constraints satisfaction, cooperation among microgrids and fairness in the use of the shared resources. Furthermore, the proposed framework guarantees an agreed cost saving to each microgrid. The described method is implemented and evaluated in a virtual testing environment that integrates accurate simulators of the microgrids. Numerical experiments show the feasibility, the computational benefits and the effectiveness of the proposed approach.