$$Mg (s) + 2HCl (aq) → MgCl_2 (aq) + H_2 (g)$$
In this reaction, magnesium metal (Mg) reacts with hydrochloric acid (HCl), which is an aqueous solution of hydrogen chloride gas. The magnesium atoms lose electrons to the hydrogen ions (H+) in the acid, resulting in the formation of magnesium ions (Mg2+) and hydrogen gas (H2). The magnesium ions then combine with the chloride ions (Cl-) from the acid to form magnesium chloride salt (MgCl2), which dissolves in the water.
Therefore, the gas produced when magnesium and hydrochloric acid are mixed is hydrogen gas (H2).