The binary neutron star merger event GW170817 was detected through both electromagnetic radiation and gravitational waves. Its afterglow emission may have been produced by either a narrow relativistic jet or an isotropic outflow. High-spatial-resolution measurements of the source size and displacement can discriminate between these scenarios. We present very-long-baseline interferometry observations, performed 207.4 days after the merger by using a global network of 32 radio telescopes. The apparent source size is constrained to be smaller than 2.5 milli-arc seconds at the 90% confidence level. This excludes the isotropic outflow scenario, which would have produced a larger apparent size, indicating that GW170817 produced a structured relativistic jet. Our rate calculations show that at least 10% of neutron star mergers produce such a jet.