The growing uncertainties in power operations due to the integration of renewable generations (RGs) and electric vehicles (EVs) into electricity grids have amplified the significance of ancillary services (AS). These services have become essential to ensure the sustainable functioning of the grid. In light of this, we introduce a two-stage optimization framework to manage competitive energy and AS markets at the interface of the transmission system (TS) and distribution system (DS). Our approach takes into account a comprehensive set of economic, technical, and security factors. This mechanism is structured in two stages: the first stage encompasses the energy market, while the second stage encompasses AS markets. Spinning reserve (SR) is supplied by conventional thermal units (TUs), whereas regulation capacity is provided by energy storage systems (ESSs), fast-response generators, electric vehicles (EVs), and demand response (DR) aggregators. We applied this mechanism to a 30-bus transmission network connected to four 10-node DSs and utilized the GUROBI solver in GAMS for solving. The simulation results demonstrate that the engagement of DSs in the SR market reduces the reliance on costly TUs, thereby decreasing system costs by approximately 10%. Furthermore, involving ESSs, EVs, and DR aggregators in the regulation market enhances technical performance and results in a 6.91% reduction in total system costs. This approach provides a robust solution to the evolving challenges posed by RGs and EVs in modern electricity grids.