Electrochemical reduction of carbon dioxide to valuable chemicals is a promising way of storing renewable energy through electric-to-chemical energy conversion, while its large-scale application is in urgent need of cheap and high-performance catalysts. Herein, we invent a convenient method to synthesize N-doped porous carbon by ammonia etching the pyrolysis carbon of petroleum pitch. We found the ammonia etching treatment not only increase the pyridinic-N content, but also enlarge the specific surface area of the petroleum pitch-based porous carbon. As a cheap and easily available catalyst for carbon dioxide electroreduction, up to 82% of Faradaic efficiency towards carbon monoxide was obtained at − 0.9 V vs the reversible hydrogen electrode in 0.1 M KHCO3. After a long time electrocatalysis of more than 20 h, the Faradaic efficiency of carbon monoxide remains 80%, indicating the porous carbon as made have an ultra-high stability as catalyst for carbon dioxide reduction. Our work provides a new technology to economically prepare efficient electrocatalysts for carbon dioxide reduction.