© The Authors, some rights reserved. Previous detections of individual astrophysical sources of neutrinos are limited to the Sun and the supernova 1987A, whereas the origins of the diffuse flux of high-energy cosmic neutrinos remain unidentified. On 22 September 2017, we detected a high-energy neutrino, IceCube-170922A, with an energy of e290 tera-electron volts. Its arrival direction was consistent with the location of a known g-ray blazar, TXS 0506+056, observed to be in a flaring state. An extensive multiwavelength campaign followed, ranging from radio frequencies to g-rays. These observations characterize the variability and energetics of the blazar and include the detection of TXS 0506+056 in very-high-energy g-rays. This observation of a neutrino in spatial coincidence with a g-ray-emitting blazar during an active phase suggests that blazars may be a source of high-energy neutrinos.