Asteroid impact. Scientists searched images of Mars to find its source crater, and two candidates seem most promising.
Another of the two possible source craters for ALH84001
The meteorites are thought to originate in impacts every one or two million years, by impactors of the scale of kilometers causing craters on Mars of diameter of tens of kilometers.
The material comes from just below the surface as that’s the material that gets into orbit from a spreading crater as it forms, perhaps a few meters down. The first meteorites probably reach Earth a century or so after impact. Earth clears its orbit in about 20 million years, and the meteorite that spent most time in transit has took about 20 million years to get here as they can tell from its cosmic radiation exposure age. See Martian meteorite - origins for a table of meteorite ages.
The youngest meteorites we have from Mars in terms of exposure age left Mars a few hundred thousand years ago. As for the materials in the meteorites, most of it is young material, volcanic, from the Mars highlands but there are a few very ancient meteorites and Allan Hills 84001 is one of those, which is why it is of especial interest.
It used to be thought to be 4.5 billion years old but new research suggests it may be 4.1 billion years old. Another meteorite has been found containing ancient zircons from Mars 4.44 billion years old, so from only a few hundred million years after the planet formed.
This is NWA 7533, nick name "Black Beauty" which is a mixture of different aged rocks but contains zircons from 4.44+-0.9 billion years ago, which is amazingly early, formed in the first 100 million years of our Solar System.
Black Beauty - the wettest meteorite from Mars and the only regolith breccia from Mars (mix of many surface rock fragments stuck together to make a single rock), like a library of 18 different rock types. It was picked up in the Sahara desert by Bedouin nomads who sold it to the scientists. When they realised how interesting it was, the nomads then went back and collected many other meteorites from the same debris field for the scientists.
For more technical details, see video of Carl B. Agee talking about the meteorite here
See also Where Should we Send our Rovers to Mars to Unravel Mystery of Origin of First Living Cells? - I’m the author of that article and copy / pasted some of the content from that article here.