Given that the metal is reactive, like magnesium is, the ions of the metal displace the hydrogen ions released by the acid and the metal ions combine with the acid's anions, forming a salt. The displaced hydrogen ions are released in the form of hydrogen gas. The reaction equation is as follows:
Acid + metal → salt + hydrogen gas