This article develops a novel multi-microgrids (MMGs) participation framework in the dayahead energy and ancillary services, i.e. services of reactive power and reserve regulation, markets incorporating the smart distribution network (SDN) objectives based on two-layer power management system (PMS). A bi-level optimization structure is introduced wherein the upper level models optimal scheduling of SDN in the presence of MMGs while considering the bilateral coordination between microgrids (MGs) and SDN's operators, i.e. second layer's PMS. This layer is responsible for minimizing energy loss, expected energy not-supplied, and voltage security as the sum of weighted functions. In addition, the proposed problem is subject to linearized AC optimal power flow (LAC-OPF), reliability and security constraints to make it more practical. Lower level addresses participation of MGs in the competitive market based on bilateral coordination among sources, active loads and MGs' operator (first layer's PMS). The problem formulation then tries to minimize the difference between MGs' cost and revenue in markets while satisfying constraints of LAC-OPF equations, reliability, security, and flexibility of the MGs. Karush-Kuhn-Tucker method is exploited to achieve a single-level model. Moreover, a stochastic programming model is introduced to handle the uncertainties of load, renewable power, energy price, the energy demand of mobile storage, and availability of network equipment. The simulation results confirm the capabilities of the suggested stochastic two-layer scheme in simultaneous evaluation of the optimal status of different technical and economic indices of the SDN and MGs.INDEX TERMS Two-layer power management system, Energy and ancillary services markets, Multi-criteria objectives, Multi-microgrids, Multi-objective bi-level optimization.