The gang allegedly waited for migrant boats to land on beaches near the southern port of Algeciras, and then promised to help migrants find their family members in Spain, police said in a statement.
The victims were then taken to a house in Algeciras where they were locked up in rooms and forced to give up their mobile phones and other personal items.
Gang members would phone the victim's family members and demand €500-€2,000 to secure their release.
They would interrogate their victims beforehand “to estimate how much they could demand from their loved ones,” the police statement said.
Police arrested five suspects as part of their investigation — three men and a woman from Morocco who were living in Spain legally and a Spanish woman.
The men allegedly carried out the kidnappings while the women kept watch over the victims.
Police said the operation remained open and they did not rule out further arrests. They did not say how many migrants they believed were kidnapped by the gang.
The authorities said they began their probe in August 2017 after becoming aware that migrants were being kidnapped shortly after they reached Spanish shores.
The port of Algeciras, near the contested British territory of Gibraltar on Spain's southern tip, is commonly used as a crossing point by migrants due to its proximity to Morocco.
Spain is the third busiest gateway for migrants arriving in Europe, still far behind Italy but catching up fast with Greece.
Many Africans undertaking the long route to Europe are choosing to avoid crossing danger-ridden Libya to get to Italy along the so-called central Mediterranean route, choosing instead to get there via Morocco and Spain.
According to the International Organization for Migration, more than 22,400 people arrived in Spain by sea last year, nearly triple the number for 2016. Some 223 people died along the way.