Three women were among the dead taken to a morgue in the Moroccan city of Nador, a medical official there said.
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.
According to Omar Naji, of the Moroccan Association of Human Rights, migrants have been making the sea crossing after authorities tightened controls at the Melilla border fence.
“Before more migrants would try to climb the Melilla fence…but now, after stricter controls, they can only cross from the sea,” he told AFP.
Naji said that migrants must pay people smugglers 3,000 euros each to undertake the sea crossing “and this traffic is carried out before the eyes of the authorities”.
Said Chramti, who heads the Grand Rif Human Rights association, told AFP that Europe is also responsible for the deaths of migrants because it is “tightening the screws on (illegal) migration”.
He also criticised the Moroccan authorities for “failing in its battle against illegal migration networks”.