At molecular level, it is challenging to construct a porous carbon from magnesium based template and low cost precursor by a facile route for supercapacitive energy storage, e.g. solvent-free approach because the coordination of magnesium ion with organic ligands usually needs participation of solvent. Herein, a balling milling mediated coordination of magnesium acetate and gallic acid was developed in the absence of solvent to prepare porous carbon. The key of the present strategy lies in the generation of volatile HAc, orienting the reaction in a favorable direction for the formation of complexes. The resultant porous carbon (denoted BGMC) owns a high microporostiy ratio (24.2 % vs template-free derived ones of 11.1 %), open accessed microstructure and hydrophobic character. As electrode for supercapacitor, in aqueous electrolyte, the BGMC based supercapacitor achieves a high energy density of 19.2 Wh kg−1@900 W kg−1, while, in organic electrolyte of 1.0 M TEABF4/AN, the symmetric device based on BGMC delivers energy in a wide voltage window of 0–3.5 V with large energy of 34.4 Wh kg−1@1750 W kg−1, which is superior to those of recently reported carbon based devices. And more, at high current density of 10 A g−1, the BGMC device can resist continual charge/discharge for 30 000 cycles, showing an excellent cycling stability. Our strategy involving solvent-freely coordination of template and precursor molecule to prepare porous carbon open up a route with facile, scalable and easy-operable attributes towards the preparation of functional porous carbon.