“The interior ministry deplores the deaths on Sunday of four illegal sub-Saharan immigrants off the town of Belyounech,” said a statement carried by the official MAP news agency.
It said the migrants, whose names and nationalities were not given, had tried to swim around a maritime fence separating the Spanish territory from Morocco.
Three others were rescued by the Moroccan navy, the statement added.
Since last year, 15 migrants have died trying to reach Ceuta by sea, and Spain has come under fire from rights groups after its border guards used rubber bullets against people trying to enter illegally.
Ceuta and Melilla, another Spanish enclave on Morocco's northern coast, form the only land border between Europe and Africa.
Last year, the Spanish authorities said they had rescued 3,500 migrants sailing aboard makeshift boats, an increase of 55 percent compared with 2013.
More than 5,000 migrants have died trying to reach Europe's shores in rickety boats over the past 18 months.