A man who went into the hospital with heart problems ended up literally coughing up a lung.

The 36-year-old was admitted to University of California San Francisco Medical Center with heart failure.

The patient had a pacemaker fitted due to a history of poor cardiovascular health, according to the New England Journal of Medicine.

During his first week of treatment, he began coughing violently, according to reports. And in the midst of one coughing fit he hawked up a bronchial tree – a series of tubes that distribute air to the lungs.

The unnamed patient died a week later.

The journal says he had a rare ejection fraction deficiency – a term for how much blood is pumped with each contraction.

His was around 50 percent less than the normal rate.

During the week, he had been coughing up blood and mucus, increasing the strain on his lungs.

Doctors were treating him with oxygen tanks.

You can’t actually cough up a whole human lung, which is too large to fit through the trachea.

But it is possible to cough so violently that parts of the organ pop through spaces between ribs, or to cough up parts.

After the patient coughed up the bronchial tree, he was immediately intubated and doctors performed a bronchoscopy.

The patient later died from heart failure complications.