A man in Spain who was declared dead by three doctors was actually still alive, which doctors discovered only when he began snoring on the autopsy table, according to news reports.

The man, 29-year-old Gonzalo Montoya Jiménez, was a prisoner at a jail in northern Spain. He was found unconscious in his cell on Sunday and was believed to be dead, according to the Spanish news outlet La Voz de Asturias. Three forensic doctors allegedly examined Jiménez and certified his death.

But four hours later, right before Jiménez's autopsy, he was heard making noises on the autopsy table, and was found to still be alive. This discovery was not a moment too soon — Jiménez's body even had the marks painted on it to guide the autopsy, a family member told La Voz de Asturias.

Get Breaking News Delivered to Your Inbox

He has now regained consciousness and is in the intensive care unit at the Central University Hospital of Asturias (HUCA) in Oviedo, Spain.

But how, exactly, does something like this happen?

Determining whether someone is dead or alive might sound simple enough, but there are not universal guidelines for exactly when doctors should pronounce someone dead. "You're dead when a doctor says you're dead," Dr. James Bernat, a neurologist at Dartmouth College's Geisel School of Medicine in New Hampshire, told Live Science in a 2014 interview.

Broadly speaking, a person may be declared dead when one of two things happens: Their heart stops beating and doesn't start again, or they are "braindead." A person is considered brain-dead when he or she no longer has any neurological activity in the brain or brain stem — meaning no electrical impulses are being sent between brain cells.

Doctors perform a number of tests to determine whether someone is brain-dead, such as checking whether the individual can initiate his or her own breath, Dr. Diana Greene-Chandos, an assistant professor of neurological surgery and neurology at Ohio State University Wexner Medical Center, told Live Science in a 2014 interview.

In the recent case, Jiménez's family said Jiménez had epilepsy, and they suspect the condition may have played a role in the unusual circumstances of his presumed death, according to La Voz de Asturias. Some people with epilepsy can experience a condition called catalepsy, or a "trancelike" state in which their muscles become rigid and they are unresponsive to stimuli.

This isn't the first time a person has been pronounced dead when they were actually alive. For example, in 2014, a 91-year-old woman in Poland was declared dead and spent 11 hours in a mortuary before staff discovered her body bag moving and found her alive, according to the BBC.

Original article on Live Science.