Dramatic police footage shows the barefoot, shirtless man dangerously positioned over the water-churning propeller of the vessel.
The Interior Ministry said the 48-year-old Algerian was immediately detained after he was spotted on board the passenger boat from Tangier, Morocco, as it arrived in Tarifa.
Authorities believe he intended to leap off the ferry and swim to shore once the vessel neared the Spanish coast, before scaling the perimeter fence at a border post.
Police said he was arrested for breaching the Immigration Act by attempting to enter the country via an unauthorised access point.
Some 61 people have already been held at Tarifa this year over similar incidents.
Tarifa, a port in southern Spain, is one of several points in the country where illegal immigrants are caught.