Finding a non-noble metal (NNM) electrocatalyst with comparative hydrogen evolution reaction (HER) activity in a broad pH range is essential but challenging. Here, we report a unique shrunken hollow spherical shell with Mo2N and Mo2C dual active phases encapsulated by nitrogen-doped carbon (Mo-N/C@N-C). As NNM electrocatalyst, it shows high HER activity and stability in a broad pH range. This material can be synthesized by pyrolysis of sulfonated polystyrene@polyaniline-MoOx sphere-like precursors using sulfonated polystyrene as template and polyaniline as carbon and nitrogen source. In an alkaline solution, the as-prepared Mo-N/C@N-C only needs an overpotential of 135 mV to reach the current density of 10 mA cm−2, and exhibits high electrochemical and structural durability. The catalyst also possesses similar performance in acidic and neutral media, making it a suitable candidate for hydrogen production in all pH media. Such excellent catalytic performance is mainly driven by the synergy of abundant Mo2N and Mo2C dual active centers, and shrunken hollow sphere structures with high packing density, as well as the N-C active site and protection of N-doped carbon frameworks.