The man, a 48-year old Algerian, made the daring crossing on board a ferry from the Moroccan city of Tangiers.
The stowaway was hiding on the right side of the boat, crouched up near the propeller of the vessel, and planned to throw himself into the water and swim to shore once he was near the Spanish coast, police said.
He was, however, spotted by agents and arrested under Spain's immigration laws.
Spanish police reported on Sunday that 61 people have so far been detained for similar attempts to enter Spain illegally in 2013.
Other methods used by people trying to enter Spain include hiding in small spaces in cars such as inside a vehicle's motor, or beneath the vehicle, police stated.