The binary neutron-star merger GW1708171 was accompanied by radiation across the electromagnetic spectrum2 and localized2 to the galaxy NGC 4993 at a distance3 of about 41 megaparsecs from Earth. The radio and X-ray afterglows of GW170817 exhibited delayed onset4–7, a gradual increase8 in the emission with time (proportional to t0.8) to a peak about 150 days after the merger event9, followed by a relatively rapid decline9,10. So far, various models have been proposed to explain the afterglow emission, including a choked-jet cocoon4,8,11–13 and a successful-jet cocoon4,8,11–18 (also called a structured jet). However, the observational data have remained inconclusive10,15,19,20 as to whether GW170817 launched a successful relativistic jet. Here we report radio observations using very long-baseline interferometry. We find that the compact radio source associated with GW170817 exhibits superluminal apparent motion between 75 days and 230 days after the merger event. This measurement breaks the degeneracy between the choked- and successful-jet cocoon models and indicates that, although the early-time radio emission was powered by a wide-angle outflow8 (a cocoon), the late-time emission was most probably dominated by an energetic and narrowly collimated jet (with an opening angle of less than five degrees) and observed from a viewing angle of about 20 degrees. The imaging of a collimated relativistic outflow emerging from GW170817 adds substantial weight to the evidence linking binary neutron-star mergers and short γ-ray bursts.