Context. There is considerable controversy surrounding the nature of M1−78, a compact nebula located beyond the Perseus arm. It was first classified as a planetary nebula and is nowadays generally considered to be a compact H ii region.Aims. To investigate the nature of M1−78 further, we present a detailed spectroscopic study of M1−78 in the optical and near-infrared. Methods. We obtained long-slit, intermediate-resolution, optical spectroscopy with the ISIS spectrograph mounted on the William Herschel Telescope (WHT) at Roque de los Muchachos Observatory (La Palma, Spain). As a complement, we obtained long-slit, intermediate-resolution, near-infrared spectra using LIRIS, the near-infrared imager/spectrographer also installed at the WHT. Results. M1−78 is a high-density nebula with substantial physical differences between its two main morphological zones: a bright arc in the SW and a blob of emission in the NE. Specifically, the blob in the NE has a higher electron temperature (13 400 K) and visual extinction (about 9 mag) than the SW arc. The most important result, however, is the confirmation of a nitrogen enrichment in M1−78. This enrichment is stronger at the location of the NE blob and is correlated with a defficiency in the O abundance and a (dubious) He enrichment. Such an abundance pattern is typical of ejecta nebulae around evolved massive stars such as Wolf-Rayet and Luminous Blue Variable stars. The spatial variations in the physical conditions and chemical abundances and the presence of more than one possible ionizing source indicate, however, that M1−78 is better described as a combination of a compact H ii region + ejecta. This is confirmed by the He i 2.112 µm/Brγ line ratio, which indicates a hot (T eff > ∼ 40 000 K) O star in the SW arc. Finally, we detect H 2 emission that extends over a large (∼30 ) area around the ionized nebula. Analysis of the near-infrared H 2 lines indicates that the excitation mechanism is UV fluorescence.