Half of all of the elements in the Universe that are heavier than iron were created by rapid neutron capture. The theory underlying this astrophysical r-process was worked out six decades ago, and requires an enormous neutron flux to make the bulk of the elements1. Where this happens is still debated2. A key piece of evidence would be the discovery of freshly synthesized r-process elements in an astrophysical site. Existing models3-5 and circumstantial evidence6 point to neutron-star mergers as a probable r-process site; the optical/infrared transient known as a `kilonova' that emerges in the days after a merger is a likely place to detect the spectral signatures of newly created neutron-capture elements7-9. The kilonova AT2017gfo—which was found following the discovery of the neutron-star merger GW170817 by gravitational-wave detectors10—was the first kilonova for which detailed spectra were recorded. When these spectra were first reported11,12, it was argued that they were broadly consistent with an outflow of radioactive heavy elements; however, there was no robust identification of any one element. Here we report the identification of the neutron-capture element strontium in a reanalysis of these spectra. The detection of a neutron-capture element associated with the collision of two extreme-density stars establishes the origin of r-process elements in neutron-star mergers, and shows that neutron stars are made of neutron-rich matter13.