Ammonia has been used in important areas such as agriculture and clean energy. Its synthesis from the electrochemical reduction of N2 is an attractive alternative to the industrial method that requires high temperature and pressure. Currently, electrochemical N2 fixation has suffered from slow kinetics due to the difficulty of N2 adsorption and N≡N cleavage. Here, N-doped porous carbon (NPC) is reported as a cost-effective electrocatalyst for ammonia synthesis from electrocatalytic N2 reduction under ambient conditions, where its N content and species were tuned to enhance N2 chemical adsorption and N≡N cleavage. The resulting NPC was effective for fixing N2 to ammonia with a high ammonia production rate (1.40 mmol g–1 h–1 at −0.9 V vs RHE). Experiments combined with density functional theory calculations revealed pyridinic and pyrrolic N were active sites for ammonia synthesis and their contents were crucial for promoting ammonia production on NPC. The energy-favorable pathway for ammonia synthesis was *N≡N → *NH═NH → *NH2–NH2 → 2NH3.