The exploration and development of cost-effective and highly stable electrocatalysts with the highest possible energy efficiency remain a constant pursuit in the catalyst design and synthesis for electrocatalytic hydrogen evolution reaction (HER). In this work, a convenient approach is proposed to synthesize a type of ultrafine Mo2C nanoparticles in average sizes of 3–4 nm embedded in hierarchically porous N-doped carbon material calcined from bimetallic ZnMo-MI (MI = 2-methylimidazole) is obtained at 1000 °C, denoted as ZnMo-MI-1000. First of all, the crystalline hybrid metal-organic framework of ZnMo-MI is fabricated from zeolitic imidazolate framework of Zn-MI precursors via solvothermal reaction, in which the conversion from Zn-MI to ZnMo-MI occurs gradually over time. After calcination, the as-obtained ZnMo-MI-1000 sample shows a satisfying HER performance with the small overpotential of 83.0 mV in 0.5 M H2SO4 and 100.1 mV in 1.0 M KOH to reach a current density of 10 mA cm−2, which is attributed to ultrasmall Mo2C, Mo and N-doped graphitic carbon matrix. The multiporous network of ZnMo-MI-1000 can provide continuous mass transportation with a minimal diffusion resistance that produce effective electrocatalytic kinetics in both acidic and alkaline media, which is utilized as a highly active and durable nonprecious metal electrocatalyst for HER.