This article proposes a novel comprehensive multi-layer power management system (PMS) along with its smart distribution network (SDN) constraints as bi-level optimization to address the participation of multi-microgrids (MMGs) in day-ahead energy and ancillary services markets. In the first layer of the proposed model, optimal programming of MMGconnected SDN is considered, in which Microgrids (MGs) participation in the markets is performed to bidirectionally coordinate sources and active loads along with the operator of MGs. In the second layer, the bidirectional coordination of operators of MGs and SDN, that is PMS, is executed in which energy loss, voltage security, and expected energy not-supplied (EENS) are minimized as weighted sum functions. The problem of the difference between costs and revenues of MGs in markets is minimized subject to constraints of linearized AC-power flow, reliability, security, and flexibility of the MGs. To obtain a singlelevel model, the Karush-Kuhn-Tucker method is applied, and a hybrid stochastic-robust programming is implemented to model uncertainties associated with the load, renewable power, energy price, mobile storage energy demand, and network equipment accessibility. The contributions of this paper include the simultaneous modelling of several economic indicators, multi-layer energy management modelling, and stochastic mixed modelling of uncertainties. The efficiency of this method is validated by simultaneously evaluating the optimum condition of technical and economic indices of several SDNs and MGs. Flexibility of 0.022 MW is obtained for the proposed scheme, which is close to zero (100% flexibility). The voltage security index is increased to 22 by the mentioned scheme, which is close to its normal value, that is, 24. The voltage deviation is below 0.07 p.u. Energy losses are reduced by about 30% compared with that in power flow studies, and the EENS reaches roughly 3 MWh, that is, close to zero (100% reliability).