The presence of solid carbonaceous matter in cometary dust was established by the detection of elements such as carbon, hydrogen, oxygen and nitrogen in particles from comet 1P/Halley. Such matter is generally thought to have originated in the interstellar medium, but it might have formed in the solar nebula—the cloud of gas and dust that was left over after the Sun formed. This solid carbonaceous material cannot be observed from Earth, so it has eluded unambiguous characterization. Many gaseous organic molecules, however, have been observed; they come mostly from the sublimation of ices at the surface or in the subsurface of cometary nuclei. These ices could have been formed from material inherited from the interstellar medium that suffered little processing in the solar nebula. Here we report the in situ detection of solid organic matter in the dust particles emitted by comet 67P/Churyumov-Gerasimenko the carbon in this organic material is bound in very large macromolecular compounds, analogous to the insoluble organic matter found in the carbonaceous chondrite meteorites. The organic matter in meteorites might have formed in the interstellar medium and/or the solar nebula, but was almost certainly modified in the meteorites’ parent bodies. We conclude that the observed cometary carbonaceous solid matter could have the same origin as the meteoritic insoluble organic matter, but suffered less modification before and/or after being incorporated into the comet.