Six Spanish civil guards and one immigrant were injured in the incident, the latest in several mass attempts to scale the wall in recent months, the government of the territory said in a statement.
About 300 people were involved in the attack, which started early in the morning. While some of the immigrants climbed the wall, others threw objects at border guards that were trying to stop them, the government said.
Spain has two enclaves in Morocco, Ceuta and Melilla. Last year, 2,841 immigrants crossed from Africa into the two territories, either swimming along the coastline, climbing the barrier or hiding in vehicles. That number was down from 2011.
Numbers for 2013 are not yet available.
The migrants were taken to an internment center where Spain attempts to establish their identity and nationality. Depending on treaties between Spain and the country of origin of each immigrant, some are repatriated and others are allowed into Spain.
Many of the migrants enter Melilla - where Spain reinforced the perimeter wall a few years ago - with no documentation.
Every year thousands of African immigrants try to reach Spanish and Italian territory on small rafts, and there are rescues and drownings almost every week.
On Monday the Spanish Coast Guard rescued 156 immigrants in seven small boats and rafts. One of the boats capsized and 42 people were thrown into the sea. The Coast Guard rescued 30 but 12 were missing, according to Spanish Television.
According to Euronews the surge of African immigrants is a direct result of the worsening situation in Sahel, the zone of transition between the Sahara desert in the North and the Sudanian savannah in the south.