Fast radio bursts are millisecond-duration, extragalactic radio flashes of unknown physical origin. The only known repeating fast radio burst source—FRB 121102—has been localized to a star-forming region in a dwarf galaxy at redshift 0.193 and is spatially coincident with a compact, persistent radio source. The origin of the bursts, the nature of the persistent source and the properties of the local environment are still unclear. Here we report observations of FRB 121102 that show almost 100 per cent linearly polarized emission at a very high and variable Faraday rotation measure in the source frame (varying from +1.46 × 105 radians per square metre to +1.33 × 105 radians per square metre at epochs separated by seven months) and narrow (below 30 microseconds) temporal structure. The large and variable rotation measure demonstrates that FRB 121102 is in an extreme and dynamic magneto-ionic environment, and the short durations of the bursts suggest a neutron star origin. Such large rotation measures have hitherto been observed only in the vicinities of massive black holes (larger than about 10,000 solar masses). Indeed, the properties of the persistent radio source are compatible with those of a low-luminosity, accreting massive black hole. The bursts may therefore come from a neutron star in such an environment or could be explained by other models, such as a highly magnetized wind nebula or supernova remnant surrounding a young neutron star.