Some of the strongest magnetic fields ever detected in the Universe come from magnetars. Now, we might finally know how these strange objects form.

Large and complex computer simulations, detailed in a new study, show that the collision of two stars can produce a massive star with a particularly strong magnetic field. As it eventually dies and goes supernova, it could end up as an exceptionally magnetic neutron star - a magnetar.

This isn't a completely new idea, but there's now some firm evidence to support it: computer modelling applied to the Tau Scorpii magnetic star, some 500 light-years away from Earth, and around 15 times the mass of our own Sun.

"Until now, we weren't able to test this hypothesis because we didn't have the necessary computational tools," says astrophysicist Sebastian Ohlmann, from the Max Planck Society in Germany.

Having previously identified that Tau Scorpii was likely the result of a merger, the star was a prime candidate for the researchers to analyse with their advanced AREPO dynamic simulation code.

Having crunched through the numbers, AREPO showed that the notable turbulence of the collision of two stars could indeed eventually lead to the strong magnetic fields we see around a star like Tau Scorpii.

When these massive magnetic stars explode at the supernova stage, magnetars could be the end result, the scientists suggest. Magnetars are notoriously difficult for astronomers to spot though, because their eruptions of magnetic energy can last for just a few hours in some cases, before they go 'quiet' again.

"Magnetars are thought to have the strongest magnetic fields in the Universe – up to one hundred million times stronger than the strongest magnetic field ever produced by humans," says astrophysicist Friedrich Röpke, from the Heidelberg Institute for Theoretical Studies in Germany.

In general, stellar mergers are relatively frequent, thought to be responsible for about 10 percent of the massive stars in the Milky Way – and the number of those stars that are magnetic is also around 1 in 10, so the maths fits from that perspective.

A further hint that this hypothesis is correct comes from the rarity of massive magnetic stars in binary systems, suggesting some kind of merger has already happened in these types of stars.

It's been quite a long road to this discovery: the idea that some massive stars could have large-scale magnetic fields near their surfaces was established in 1947, though their origin has remained a mystery since then. Magnetic fields around smaller stars, like our own Sun, have been easier for scientists to explain.

What's certain is there's plenty more still to find out about these massive magnetic stars - and the high-strength magnetars that some of them develop into.

The research has been published in Nature.