Agents used heartbeat detectors and dogs to locate the migrants who had hidden anywhere they could find -- including bumper cars and a ghost train - as the vehicles carrying them waited to board ferries bound for mainland Spain, the Guardia Civil police force said.
"They try to use attractions that are only half covered up to jump in and hide inside," a spokesman told AFP.
The funfair takes place every year in Ceuta, a Spanish territory on Morocco's northern coast, as part of annual celebrations in honour of the city's patron saint, the "Virgin of Africa."
It involves some 350 vehicles carrying everything from fairground rides to ticket booths, the spokesman said, all of which board ferries to return to mainland Spain once the festival is over.
He said the fairground vehicles had started boarding ferries early on Monday morning, and by late Tuesday afternoon, there were still a dozen left to go.
Ceuta and Melilla, another small Spanish territory on the same coast, have the EU's only land borders with Africa.
As a result, they are entry points for migrants desperate to get to Europe and who regularly try to climb high double border fences, swim along the coast or hide in vehicles crossing the frontier.
In recent days, migrants have repeatedly stormed the frontier with Ceuta by either attempting to cut through the wire fencing or running through the border post.
Once on Spanish soil in Ceuta, they are taken to migrant reception centres where they can apply for asylum.
But many are desperate to get to mainland Spain, believing that the process in Ceuta is slow or fearing that they will be returned to neighbouring Morocco, and try to hide in lorries boarding ferries.