A dodecahedral activated N-doped porous carbon scaffold is synthesized and used for the nanoconfinement of Mg(BH4)2. The optimized mesoporous scaffold possesses an accumulated pore width of 2.65nm, high specific surface area (3955.9 m2g-1), and large pore volume (2.15 cm3g-1), providing ample space for the confinement of Mg(BH4)2 particles and numerous surface active sites for interactions with the same. The confined Mg(BH4)2 system features a dehydrogenation onset temperature of 81.5°C, an extremely high capacity of 10.2 wt% H2, and an almost single-step dehydrogenation profile. Moreover, the system exhibits superior capacity retention of 82.7% after 20 cycles at a moderate temperature of 250°C. Precise activation control enables a transformation from microporous carbon materials to mesoporous ones, and hence the efficient nanoconfinement of Mg(BH4)2 and realization of one-step dehydrogenation. The evolution of borohydride intermediates is systematically revealed throughout the cycling process. Density functional theory calculations demonstrate defective N heteroatoms within the scaffold are vital in reducing the strength of B─H bonds, and the N-doped carbon can facilitate decomposition of the irreversible MgB12H12 intermediate. This study opens up new avenues for designing robust carbon scaffolds doped with heteroatoms and analyzing intermediate evolution in nanoconfined Mg-based borohydride systems.