This Article Develops a Novel Multi-Microgrids (MMGs) Participation Framework in the Day-Ahead 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.