Mesoporous nitrogen-doped carbon nanoparticles with atomically dispersed iron sites (named mesoNC-Fe) are synthesized via high-temperature pyrolysis of an Fe containing ZIF-8 MOF. Hydrolysis of tetramethyl orthosilicate (TMOS) in the MOF framework prior to pyrolysis plays an essential role in maintaining a high surface area during the formation of the carbon structure, impeding the formation of iron (oxide) nanoparticles. To gain inside on the nature of the resulting atomically dispersed Fe moieties, HERFD-XANES, EXAFS and valence-to-core X-ray emission spectroscopies have been used. The experimental spectra (both XAS and XES) combined with theoretical calculations suggest that iron has a coordination sphere including a porphyrinic environment and OH/H2O moieties responsible for the high activity in CO2 electroreduction. DFT calculations demonstrate that CO formation is favored in these structures because the free energy barriers of *COOH formation are decreased and the adsorption of *H is impeded. The combination of such a unique coordination environment with a high surface area in the carbon structure of mesoNC-Fe makes more active sites accessible during catalysis and promotes CO2 electroreduction.