The migrants were spotted by Spanish soldiers shortly after they landed on Congress Island about four kilometres (2.5 miles) off Morocco.
The soldiers gave the migrants food and water and they were returned to Morocco after medical checks determined they were in good health, the Spanish government's representative in Melilla, which is close to the island, said in a statement.
Spain has two exclaves on Africa's northern Mediterranean coast, Melilla and Ceuta, and several tiny islands off it.
Congress Island -- one of three islands that make up the Chafarinas archipelago -- measures about 25 hectares (60 acres).
"We obviously cannot allow another route to illegal immigration to open," Abdelmalik El Barkani, the Spanish government's representative in Melilla, said in the statement.
"This is a very delicate situation in which we must all act responsibly, and when I say all I refer to Spain, Morocco and the European Union. We have to take into account that we are talking about territories very close to the coast of a third country that can't become an illegal access to Melilla or the mainland, at the service of mafias that traffic people."
Many migrants from Africa try dangerous crossings to reach Spanish territory illegally in the hope of gaining work and forging a better life.
Would-be migrants try to storm the border fence around Melilla, which along with Ceuta have Europe's only two land borders with Africa.
Other migrants have tried to sail to Spain's north African territories or to the European mainland in flimsy vessels or enter the country hidden under car seats.
Human Rights Watch last month slammed Spanish authorities for summarily returning irregular immigrants to Morocco from Ceuta and Melilla.
It said the practice violated Spanish, European and international law, especially as "migrants forced back into Morocco face violence and other abuse at the hands of Moroccan security forces."