A new study has offered fresh insights into where Mars’ two misshapen little moons — Phobos and Deimos — came from. The paper, published in the journal Nature Geoscience, details a tumultuous and violent origin story, involving, among other things, a collision between Mars and a massive object and a third, much larger moon that fell back on Mars a few million years after its formation.

“This research is important because it suggests we may still have a lot to learn about how moons form and evolve, even on our closest planetary neighbors,” Benjamin Black, a planetary scientist at the City University of New York, who was not involved in the research, told the Guardian. “It also underscores how quickly and dramatically planetary systems can evolve early in their history.”

According to the study, based on a series of computer simulations that explored possible scenarios, here’s how the events probably unfolded:

Billions of years ago, when Mars was still an infant, a large object — about a third the size of the planet — smashed into it, hurling out debris and leaving a huge dent on the planet’s surface — a region scientists now believe is the large Borealis basin in the northern hemisphere. A similar event is believed to have formed our moon roughly 4.5 billion years ago.

Once this debris was ejected, it rapidly accreted to formed a disc around the planet, eventually leading to the creation of a large "transient" moon in the region where the debris density was the highest. The gravitational pull of the moon, which the researchers estimate had a diameter of nearly 125 miles, then helped concentrate material in the outer regions of the disc, where the debris would originally have spread too sparsely to form any large bodies.

However, the large moon was unstable and just five million years after it formed, it broke up and was dragged inward by Mars’ gravity.

“The trick is that this moon, which has played a major role in the process, has now disappeared,” Pascal Rosenblatt from the Royal Observatory of Belgium told the Guardian. “It would have broken into very small parts that could in fact burn through the atmosphere or create very, very small impact craters.”