A cosmic mystery has just been solved with violence.

A pair of stars named HD 148937 doesn't look the way we think it should because, once upon a time, they were three. A new study has found that two of the original stellar trinary merged, producing not just the beautiful Dragon's Egg nebula in which the stars are ensconced, but two mismatched stars, bound together in a gravitational dance.

"When doing background reading, I was struck by how special this system seemed," says astronomer Abigail Frost of KU Leuven in Belgium and the European Southern Observatory in Chile.

"A nebula surrounding two massive stars is a rarity, and it really made us feel like something cool had to have happened in this system. When looking at the data, the coolness only increased."

The system, located around 3,800 light-years from Earth, consists of two massive stars locked in a 26-year orbit. And these are massive – one clocking in at 29.9 and the other at 26.6 times the mass of the Sun. That's big enough, theory suggests, that each star will form a black hole when it dies.

Visible light image of the Dragon's Egg nebula and the binary star at its center. (ESO/VPHAS+ team. Acknowledgement: CASU)

The larger of the two stars is really curious. Previous research suggests that it has a magnetic field. This is really strange, because stars larger than about seven times the mass of the Sun usually don't – they don't seem to have the convective interiors that are required to maintain a magnetic field the way smaller stars do.

This is what piqued the interest of Frost and her team. They analyzed nine years' worth of observational data on the system, collected with the ESO's Very Large Telescope, as well as archival data from the MPG/ESO 2.2-meter telescope. This allowed them to characterize the stars and their orbit in detail.

And when they started looking closer, the researchers noticed something strange. Two massive stars in a binary like this one should be about the same age, having formed in the same stellar nursery at around the same time.

But when the researchers analyzed the chemical composition of the stars – the profile of which helps determine their age – they found that the larger of the two stars appears to be about 2.7 million years old, and the smaller at least 4.1 million years old. That's not an insignificant age difference.

And then there's the nebula, which is estimated to be around 7,500 years old. Its presence alone is strange enough; such nebulas are usually emitted by dying stars, but both stars in the nebula's core are very much in the prime of their life.

And then there's a whole lot of nitrogen, carbon, and oxygen in it. Usually these elements are sequestered inside stars, not billowing around outside them.

One possible explanation that has been put forth for magnetic massive stars is the merger of two smaller stars. Such an event could release internal star material into the space around them, too. Together, the clues suggest that such a merger is indeed what took place in HD 148937.

"We think this system had at least three stars originally; two of them had to be close together at one point in the orbit whilst another star was much more distant," says astronomer Hugues Sana of KU Leuven.

"The two inner stars merged in a violent manner, creating a magnetic star and throwing out some material, which created the nebula. The more distant star formed a new orbit with the newly merged, now-magnetic star, creating the binary we see today at the center of the nebula."

This would make HD 148937 the first compelling evidence that stellar mergers do indeed result in the magnetic fields we occasionally see wrapped around massive stars. The rate at which these mergers are expected to occur is consistent with the percentage of massive stars we see that have magnetic fields.

And, because these magnetic fields are thought to be very cosmically fleeting, that aligns with a relatively recent timeframe for the merger, too – consistent with the estimated age range of the Dragon's Egg nebula.

The team's research has been published in Science.