Astronomers have for the first time detected an ageing star swallowing a planet, possibly indicating the fate of Earth some day.

The planet was likely about the size of Jupiter, with an orbit even closer to its star than Mercury's is to the Sun.

Describing in a study published in the journal Nature, they said that after running out of fuel in its core, the star began to grow in size, shrinking the gap with its neighbouring planet, eventually consuming it entirely.

In about 5 billion years, our Sun will go through a similar ageing process, possibly reaching 100 times its current diameter and becoming what's known as a red giant. During that growth spurt, it will absorb Mercury, Venus, and possibly Earth.

Astronomers have previously identified many red giant stars and suspected that in some cases they consume nearby planets, but the phenomenon had never been directly observed before.

"This type of event has been predicted for decades, but until now, we have never actually observed how this process plays out," said lead author Kishalay De, an astronomer at the Massachusetts Institute of Technology in Cambridge.

The star devouring event - formally called ZTF SLRN-2020 - was detected using multiple ground-based observatories and NASA's NEOWISE (Near Earth Object Wide Field Infrared Survey Explorer) spacecraft.

Drag from the atmosphere slowed the planet down, shrinking its orbit and eventually sending it below the star's visible surface, like a meteor burning up in Earth's atmosphere.

The transfer of energy caused the star to temporarily increase in size and become a few hundred times brighter.

Recent observations show the star has returned to the size and brightness it was before merging with the planet.

The flash of optical light (visible to the human eye) after the planet's demise first showed up in observations by the Caltech-led Zwicky Transient Facility (ZTF), an instrument based at Palomar Observatory in Southern California that looks for cosmic events that change in brightness rapidly, sometimes in a matter of hours.

Further, the astronomers turned to the NEOWISE observatory, which scans the entire sky in infrared light (a range of wavelengths longer than visible light) every six months.

Looking at the NEOWISE data, De saw that the star brightened almost a year before ZTF spotted the flash.

That brightening was evidence of dust (which emits infrared light) forming around the star.

De and his colleagues think the dust indicates that the planet didn't go down without a fight and that it pulled hot gas away from the puffy star's surface as it spiralled toward its doom.

As the gas drifted out into space, it would have cooled and become dust - like water vapour becoming snow. Even more gas was then flung into space during the collision of the star and the planet, producing more dust visible to both the ground-based infrared observatories and NEOWISE.

"Very few things in the universe brighten in infrared light and then brighten in optical light at different times," said De. "So the fact that NEOWISE saw the star brighten a year before the optical eruption was critical to figuring out what this event was."

Five billion years from now, when our Sun is expected to become a red giant, swallowing up Mercury, Venus, and possibly Earth, the light show should be much more subdued, according to De, since those planets are many times smaller than the Jupiter-size planet in the ZTF-captured event.

The new observations provide astronomers with a template for what those events should look like, opening up the possibility of finding more.