The bodies of the victims including one woman washed ashore at Ain Harrouda, 17 kilometres (10 miles) from Casablanca on the kingdom's Atlantic coast, after their inflatable boat got a puncture and sank, authorities said.
Three survivors were found unconscious and taken to hospital, the official MAP press agency reported citing the officials.
The number of migrants aboard the vessel was unknown.
Since January, more than 15,000 migrants have arrived in Spain by sea, according to Spanish authorities.
Many depart from Morocco's northern Mediterranean coast, just a few dozen kilometres from the south of Spain.
But overall arrivals to Spain by sea have decreased significantly this year.
Last year, Moroccan authorities stopped some 89,000 “irregular immigration attempts”, of which 29,000 were by sea, according to official figures.
The European Union committed 140 million euros ($155 million) in 2018 towards managing migration from Morocco.
The migrants come mostly from West African countries, but in the past two years increasing numbers of young Moroccans have tried to leave, driven by searing inequality in the country.