Security forces drove back the migrants, who tried to storm a three-tier barbed wire border fence that separates Morocco from Melilla, a Spanish territory.
It is the latest in a string of desperate attempts to breach the fence. Hundreds have scrambled across in recent months, but the border was recently fortified with mesh fences and Spanish security forces have increased patrols.
Melilla is one of two Spanish-held cities on the northern coast of Africa, the other being Ceuta to the east. The number of migrants attempting to cross has risen in recent months, many trying in groups to try and overwhelm border guards.
"Anti-climbing mesh and the collaboration of the Moroccan forces with the (Spanish) civil guard managed to stop an attempt to cross by about a thousand migrants," the Spanish government delegation in Melilla said.
"None of the immigrants managed to reach the city," it added.
According to estimates by the Interior Ministry in Madrid, about 40,000 Africans of sub-Saharan origin are waiting for an opportunity to go to Spain. The immigrant reception center in Melilla is understood to be highly overcrowded.
There has also been a recent increase in the number of boats trying to reach Europe from North Africa, often originating in Libya, where criminal gangs organizing boat trips have flourished amid the breakdown of law and order in the country.
Most of the migrants come from Eritrea or Syria, with others fleeing impoverished parts of sub-Saharan Africa.
Italian officials said in early June that almost 47,000 people had arrived from North Africa by sea since the beginning of this year, a tenfold increase over the same period in 2013.
Thousands of migrants have died at sea in recent years trying to reach Europe, as they often make the attempt in badly overcrowded and unseaworthy vessels.
Italy and Spain have asked for more help from the EU in securing their borders and dealing with the crisis.
jr/lw (dpa, AP, AFP)