The kinetic process of a slow oxygen evolution reaction (OER) always constrains the efficiency of overall water electrolysis for H2 production. In particular, nonprecious metal electrodes for the OER have difficulty simultaneously possessing good electrocatalytic activity and long-term stability in pH-universal media. In this work, urea is first used as a pore-forming agent and active C/N source to fabricate a nanoporous NiFeCoCN medium-entropy alloy (MEA) by high-temperature sintering based on the nanoscale Kirkendall effect. The NiFeCoCN MEA achieves an overpotential of 432 mV at a current density of 10 mA cm-2 and a lower Tafel slope of 52.4 mV dec-1 compared to the IrO2/Ti electrode (58.6 mV dec-1) in a 0.5 M H2SO4 solution. In a 1 M KOH solution, the NiFeCoCN MEA obtains an overpotential of 177 mV for 10 mA cm-2 and a Tafel slope of 36.1 mV dec-1, which is better than IrO2/Ni foam. This work proves a novel strategy to design and prepare nanoporous MEA materials with desirable C/N species, which provides promising prospects for the industrial production of H2 energy.