A man who later died stunned doctors by coughing up a six-inch-wide blood clot from his lungs in the near-perfect shape of his right bronchial tree.

The mysterious, cherry-red cast resembles a piece of coral and an image of it has gone viral after appearing in the New England Journal of Medicine.

It came from a 36-year-old man with end-stage heart failure who spat out the medical anomaly in one piece during a coughing fit in hospital.

The doctors treating the patient were “astonished” after they unfurled the clot to find it had retained the shape of the lung pathway from which it came.

Despite the best efforts of intensive care staff at the University of California San Francisco Medical Center, the man died a week later.

“We were astonished,” pulmonary surgeon Georg Wieselthaler told The Atlantic of the clot.

“It’s a curiosity you can’t imagine — I mean, this is very, very, very rare.”

The image of the clot has been widely shared because of how simultaneously grotesque and fascinating it is, with mixed reactions.

The patient, who had a history of heart problems, had been placed on oxygen and given blood thinners to help circulate blood and prevent clogging.

But blood eventually broke into his lungs and after days of coughing up smaller clots, the patient hawked up the famous one, giving new meaning to the phrase “coughed up a lung”.