Three women were among the dead taken to a morgue in the Moroccan city of Nador, a medical official there told AFP.
All were sub-Saharan Africans apart from one Moroccan, the official said.
A spokeswoman for Melilla’s authorities earlier said “about 20” bodies had been recovered in Moroccan territorial waters.
The bodies of the migrants were spotted Saturday by a Spanish ship, which alerted the rescue services of both countries, she said.
Late Saturday, a Spanish police patrol boat found one more body, which was taken to Melilla, a Spanish enclave bordering Morocco.
Spanish authorities said a Civil Guard helicopter was supporting Moroccan search patrols on Sunday morning.
Migrants are increasingly favouring the so-called western Mediterranean route to reach Europe, which involves making the sea crossing between North Africa and southern mainland Spain.
According to the International Organization for Migration, Spain has been the second most popular point of entry for migrants coming to Europe so far this year, with 1,279 arrivals, after Italy with 4,256.
It said 243 people have died or are missing in the Mediterranean after trying to cross the sea this year, not including those recovered this weekend.
Spain was last year the third point of entry for Europe-bound migrants, after Italy and Greece.
Arrivals by sea tripled in 2017 compared to the previous year, reaching a total of 22,900 migrants, according to the EU border agency Frontex.