Gamma-ray bursts (GRBs) of the long-duration class are the most luminous sources of electromagnetic radiation known in the Universe. They are generated by outflows of plasma ejected at near the speed of light by newly formed neutron stars or black holes of stellar mass at cosmological distances. Prompt flashes of MeV gamma rays are followed by longer-lasting afterglow emission from radio waves to GeV gamma rays, due to synchrotron radiation by energetic electrons in accompanying shock waves. Although emission of gamma rays at even higher, TeV energies by other radiation mechanisms had been theoretically predicted, it had never been detected previously. Here we report the clear detection of GRB 190114C in the TeV band, achieved after many years of dedicated searches for TeV emission from GRBs. Gamma rays in the energy range 0.2--1 TeV are observed from about 1 minute after the burst (at more than 50 standard deviations in the first 20 minutes). This unambiguously reveals a new emission component in the afterglow of a GRB, whose power is comparable to that of the synchrotron component. The observed similarity in the radiated power and temporal behaviour of the TeV and X-ray bands points to processes such as inverse Compton radiation as the mechanism of the TeV emission, while processes such as synchrotron emission by ultrahigh-energy protons are disfavoured due to their low radiative efficiency.