The hydrogen evolution reaction (HER) is a crucial step in electrochemical water splitting and demands an efficient, durable and cheap catalyst if it is to succeed in real applications. For an energy-efficient HER, a catalyst must be able to trigger proton reduction with minimal overpotential and have fast kinetics. The most efficient catalysts in acidic media are platinum-based, as the strength of the Pt-H bond is associated with the fastest reaction rate for the HER. The use of platinum, however, raises issues linked to cost and stability in non-acidic media. Recently, non-precious-metal-based catalysts have been reported, but these are susceptible to acid corrosion and are typically much inferior to Pt-based catalysts, exhibiting higher overpotentials and lower stability. As a cheaper alternative to platinum, ruthenium possesses a similar bond strength with hydrogen (∼65 kcal mol -1)16, but has never been studied as a viable alternative for a HER catalyst. Here, we report a Ru-based catalyst for the HER that can operate both in acidic and alkaline media. Our catalyst is made of Ru nanoparticles dispersed within a nitrogenated holey two-dimensional carbon structure (Ru@C2N). The Ru@C2N electrocatalyst exhibits high turnover frequencies at 25 mV (0.67 H2 s-1 in 0.5 M H2SO4 solution; 0.75 H2s-1 in 1.0 M KOH solution) and small overpotentials at 10 mA cm-2 (13.5 mV in 0.5 MH2SO4 solution; 17.0 mV in 1.0 M KOH solution) as well as superior stability in both acidic and alkaline media. These performances are comparable to, or even better than, the Pt/C catalyst for the HER.