Border officers found the two after the van disembarked from a ship at the southern Spanish port of Tarifa, which faces the coast of Morocco, police said in a statement.
A third Moroccan minor and an adult were also caught in the same port a few hours later hiding in the motor unit of a boat which had sailed from Tangiers in Morocco, the statement added.
In the case of the camper van, "the two children were trying to reach Spain hiding below the undercarriage of the vehicle and clinging onto it, putting their lives in grave danger," it said.
"They were exposed in a very small space to extreme temperatures caused by the weather and also by the vehicle's engine."
They were the latest of thousands of migrants from Africa to risk their lives trying to reach Europe.
Many sail across to Spain from Morocco in flimsy boats or hide themselves in vehicles.
Thousands of others try to scramble over the tall fences dividing Morocco from two Spanish territories on the north African coast, Ceuta and Melilla.