Long-duration γ-ray bursts (GRBs) are the most luminous sources of electromagnetic radiation known in the Universe. They arise from outflows of plasma with velocities near the speed of light that are ejected by newly formed neutron stars or black holes (of stellar mass) at cosmological distances1,2. Prompt flashes of megaelectronvolt-energy γ-rays are followed by a longer-lasting afterglow emission in a wide range of energies (from radio waves to gigaelectronvolt γ-rays), which originates from synchrotron radiation generated by energetic electrons in the accompanying shock waves3,4. Although emission of γ-rays at even higher (teraelectronvolt) energies by other radiation mechanisms has been theoretically predicted5-8, it has not been previously detected7,8. Here we report observations of teraelectronvolt emission from the γ-ray burst GRB 190114C. γ-rays were observed in the energy range 0.2-1 teraelectronvolt from about one minute after the burst (at more than 50 standard deviations in the first 20 minutes), revealing a distinct emission component of the afterglow with power comparable to that of the synchrotron component. The observed similarity in the radiated power and temporal behaviour of the teraelectronvolt and X-ray bands points to processes such as inverse Compton upscattering as the mechanism of the teraelectronvolt emission9-11. By contrast, processes such as synchrotron emission by ultrahigh-energy protons10,12,13 are not favoured because of their low radiative efficiency. These results are anticipated to be a step towards a deeper understanding of the physics of GRBs and relativistic shock waves.