A dramatic encounter between two stars has strewn their remains out across their little corner of space in the most spectacular fashion - and we get to actually see it with our own eyes.

Here's how it went down: As a dying star expanded into a red giant, it engulfed another, lower mass star. The latter started to spiral towards the red giant, causing it to throw off its outer layers prematurely, and bringing its evolution to a halt.

The result? A complex cloud of gas that has perplexed astronomers for decades. Now, using the powerful capabilities of the Atacama Large Millimeter/submillimeter Array (ALMA), the secrets of the star system HD 101584 have come to light.

Stars that are roughly the mass of our Sun have a known evolutionary path. When they have fused all the hydrogen in their cores to helium, the nuclear fusion within ceases, and the core starts to contract. This brings more hydrogen into the region immediately around the core, forming a hydrogen shell; then, fusion starts up again, dumping helium into the core. This is called hydrogen shell burning.

During this time, the outer layers of the star expand by a lot. When this eventually happens to the Sun, for example, it will expand out past the orbit of Mars. This is the red giant branch of stellar evolution.

When all the hydrogen has been fused, the star will start fusing helium. And when all the helium in the core has fused into oxygen and carbon, the core contracts again, and the star will start expanding again. This is the asymptotic giant branch.

A 1995 paper describing HD 101584 as a "peculiar supergiant" concluded that the star was on the post-asymptotic giant branch. But ALMA's observations suggest that the star's evolution was cut off at the red giant branch before it was utterly dismembered.

"The star system HD 101584 is special in the sense that this 'death process' was terminated prematurely and dramatically as a nearby low-mass companion star was engulfed by the giant," said astronomer Hans Olofsson of the Chalmers University of Technology in Sweden.

Based on the team's reconstruction of what happened, that event was preeetty violent.

The dying star was doing its red giant branch thing, puffing out into the surrounding space. This surrounding space, however, just so happened to include its smaller companion star. When the red giant's envelope engulfed the smaller star, the smaller star spiralled in towards the red giant's core - but stopped short of colliding with it.

This caused the red giant to go absolutely berserk. It erupted prematurely, explosively ejecting its gas layers, and is currently in the process of exposing the naked core. It was total carnage - leaving behind a gorgeous complex nebula of star guts, carved out by the smaller star's death spiral.

The astronomers were also able to resolve two jets, shooting from the red giant's poles. These blew into the already ejected gas and dust, creating the rings of gas you see in the picture above.

Although the scenario is an unusual one, it can help astronomers to connect the dots between the evolutionary stages of stars.

"Currently, we can describe the death processes common to many Sun-like stars, but we cannot explain why or exactly how they happen," said astronomer Sofia Ramstedt of Uppsala University in Sweden.

"HD101584 gives us important clues to solve this puzzle since it is currently in a short transitional phase between better studied evolutionary stages.

"With detailed images of the environment of HD101584, we can make the connection between the giant star it was before, and the stellar remnant it will soon become."

The research has been published in Astronomy & Astrophysics.