Young migrants were taken to hospital after they were found crammed inside car engines and dashboards.
Photos show a 15-year-old girl and two men, believed to be 20 and 21 years old, desperately trying to hide in the cars, all stopped at customs in Beni Ansar, Morocco, in the space of three hours.
The migrants were hoping for a new life in the European Union (EU) but these hopes were dashed.
A 20-year-old man was found in the base of a truck in nearby Melilla, north of Beni Ansar in port territory owned by Spain.
Two of the four migrants had to be treated in hospital.
It's believed they had suffered disorientation, joint pain and from a loss of oxygen due to the way they had been travelling.
All of the drivers have now been detained and will appear in court, police said.
They were all Moroccan, aged 19, 30 and 31, but had no ties with Melilla, a city owned by Spain.
Ferries frequently leave the port there for the EU.
A migrant was found hidden in a suitcase as he tried to smuggle himself into Spain last month.
The 19-year-old was pictured inside the bag in Ceuta, another Spanish enclave.
The Moroccan woman who was carrying the suitcase was arrested.