Passers-by in the port of Tarifa told officers Monday they had spotted a man in visibly poor condition drifting at sea in high winds and strong waves, according to a police statement.
Police rescued him and emergency services rushed him to hospital.
Wearing only a white shirt, the man was "gripping a rigid life buoy fitted with a beacon," police said.
"He presented signs of extreme hypothermia, bloated lips, face and eyes, and swollen eyelids due to exposure to the sun and salty water," indicating he had been adrift for several hours, according to the police.
They added the man also had bruises.
Police later discovered the mystery man was the captain of the "Morning Ninni", a cargo ship from Singapore that had been sailing close to the Spanish territory of Ceuta in northern Morocco across the Gibraltar strait.
The ship, which according to specialised sites is a vehicle transport vessel, had alerted Spanish rescue services that a man "may have fallen overboard", that morning, police said.