The inflatable boats were stopped as they crossed the Strait of Gibraltar and the would-be migrants, mostly from sub-Saharan Africa, were given blankets and taken to the Spanish port of Tarifa, the maritime services said in a statement.
The Strait of Gibraltar separates Spain and Morocco by around just 15 kilometres (nine miles) — a ferry ride between the two continents takes roughly 35 minutes — making it one of the key smuggling routes for illegal immigrants crossing into Europe.
Thousands of illegal migrants from Africa regularly attempt to cross from Morocco into Spain on makeshift boats each year.
Authorities fear many of those who attempt the crossing by sea die of thirst, hunger or exposure.
In October at least 16 African migrants died while trying to reach Spain from Morocco by boat.
Two African migrants were found dead on October 26 on a boat carrying about 50 other would-be migrants, a day after 14 others were pulled dead from the water after their attempt to reach Spain on another raft failed.