Gamma-ray bursts (GRBs) are brief flashes of γ-rays and are considered to be the most energetic explosive phenomena in the Universe1. The emission from GRBs comprises a short (typically tens of seconds) and bright prompt emission, followed by a much longer afterglow phase. During the afterglow phase, the shocked outflow—produced by the interaction between the ejected matter and the circumburst medium—slows down, and a gradual decrease in brightness is observed2. GRBs typically emit most of their energy via γ-rays with energies in the kiloelectronvolt-to-megaelectronvolt range, but a few photons with energies of tens of gigaelectronvolts have been detected by space-based instruments3. However, the origins of such high-energy (above one gigaelectronvolt) photons and the presence of very-high-energy (more than 100 gigaelectronvolts) emission have remained elusive4. Here we report observations of very-high-energy emission in the bright GRB 180720B deep in the GRB afterglow—ten hours after the end of the prompt emission phase, when the X-ray flux had already decayed by four orders of magnitude. Two possible explanations exist for the observed radiation: inverse Compton emission and synchrotron emission of ultrarelativistic electrons. Our observations show that the energy fluxes in the X-ray and γ-ray range and their photon indices remain comparable to each other throughout the afterglow. This discovery places distinct constraints on the GRB environment for both emission mechanisms, with the inverse Compton explanation alleviating the particle energy requirements for the emission observed at late times. The late timing of this detection has consequences for the future observations of GRBs at the highest energies.