Oxygen electrocatalysis is of great importance for many energy storage and conversion technologies, including fuel cells, metal–air batteries and water electrolysis. Replacing noble metal-based electrocatalysts with highly efficient and inexpensive non-noble metal-based oxygen electrocatalysts is critical for the practical applications of these technologies. Here we report a general approach for the synthesis of hollow frameworks of nitrogen-doped carbon nanotubes derived from metal–organic frameworks, which exhibit higher electrocatalytic activity and stability for oxygen reduction and evolution than commercial Pt/C electrocatalysts. The remarkable electrochemical properties are mainly attributed to the synergistic effect from chemical compositions and the robust hollow structure composed of interconnected crystalline nitrogen-doped carbon nanotubes. The presented strategy for controlled design and synthesis of metal–organic framework-derived functional nanomaterials offers prospects in developing highly active electrocatalysts in electrochemical energy devices.