Studying the nature of various types of supernovae (SNe) is important for our understanding of stellar evolution. Observations of atomic and molecular gas in the host galaxies of gamma-ray bursts (GRBs) and SNe have recently been used to learn about the nature of the explosions themselves and the star formation events during which their progenitors were born. Based on archival data for M 74, which previously has not been investigated in the context of SN positions, we report the gas properties in the environment of the broad-lined type Ic (Ic-BL) SN 2002ap and the type II SNe 2003gd, 2013ej, and 2019krl. The SN 2002ap is located at the end of an off-centre, asymmetric, 55 kpc-long HIextension containing 7.5% of the total atomic gas in M 74, interpreted as a signature of external gas accretion. It is the fourth known case of an explosion of a presumably massive star located close to a concentration of atomic gas (after GRBs 980425, 060505, and SN 2009bb). It is unlikely that all these associations are random (at a 3σsignificance), so the case of SN 2002ap adds to the evidence that the birth of the progenitors of type Ic-BL SNe and GRBs is connected with the accretion of atomic gas from the intergalactic medium. The HIextension could come from tidally disrupted companions of M 74, or be a remnant of a galaxy or a gas cloud that accreted entirely from the intragroup medium. The other (type II) SNe in M 74 are located at the outside edge of a spiral arm. This suggests that either their progenitors were born when gas was piling up there or that the SN progenitors moved away from the arm due to their orbital motions. These type II SNe do not seem to be related to gas accretion.