Image copyright AP Image caption A red line still marks the spot where doctors removed a tapeworm from Luis Ortiz's head

A California man is recovering after he had a live tapeworm removed from his brain during emergency surgery.

Luis Ortiz was admitted to a hospital in Napa with what he called the worst headache of his life.

In a brain scan, neurosurgeon Soren Singel discovered the larva of a tapeworm and told Mr Ortiz he had about 30 minutes to live.

The tapeworm grew inside a cyst that cut off circulation and water flow to the rest of his brain.

"I stood up and then I threw up," said Mr Ortiz. "The doctor pulled it out and he said it was still wiggling, and I'm like 'Ugh, that doesn't sound too good.'"

The US Centers For Disease Control and Prevention (CDC) reports larval cysts in the brain - neurocysticercosis - develop after a person swallows microscopic eggs passed in the faeces of a person who has an intestinal pork tapeworm.

Once inside the body, those eggs hatch and the worms can make their way to the brain. The CDC says approximately 1,000 people per year are hospitalised for neurocysticercosis and removal of the larvae.

Mr Ortiz is recovering after the surgery in August and is hoping to return to Sacramento State University, where he was scheduled to begin his final year before the surgery.

"It's probably more gratifying to me to be living, because if I would have waited a little bit longer, then I probably wouldn't be here right now," he told CBS San Francisco.