Kilonovae are a rare class of astrophysical transients powered by the radioactive decay of nuclei heavier than iron, synthesized in the merger of two compact objects 1–4 . Over the first few days, the kilonova evolution is dominated by a large number of radioactive isotopes contributing to the heating rate2, 5 . On timescales of weeks to months, its behavior is predicted to differ depending on the ejecta composition and merger remnant6–9 . However, late-time observations of known kilonovae are either missing or limited10, 11 . Here we report observations of a luminous red transient with a quasi-thermal spectrum, following an unusual gamma-ray burst of long duration. We classify this thermal emission as a kilonova and track its evolution up to two months after the burst. At these late times, the recession of the photospheric radius and the rapidly-decaying bolometric luminosity (Lbol ∝ t −2.7±0.4) support the recombination of lanthanide-rich ejecta as they cool.