About 200 people got over into Melilla and were taken to a reception center, Spanish authorities said.
The assailants who failed to enter the enclave would be returned to their home countries, the Moroccan Interior Ministry said in a statement.
Public forces intervened to thwart this assault attempt and proceeded to the arrest of 141 illegal migrants, the ministry said, adding that 12 soldiers and a member of the auxiliary forces were wounded during this operation.
While trying to escalate the fence, one person fell from the top of the fence and died while 22 assailants were injured by barbed wire and transferred to the hospital to receive the necessary care, the Interior Ministry said in the statement.
More than 43,000 migrants have made the crossing to Spain since the start of the year, including around 38,000 by sea, according to the UN International Organization for Migration (IOM).
Moroccan authorities have so far this year foiled 54,000 attempts by illegal migrants to cross to Europe, it was officially reported last month.
Rabat said it had dismantled 74 “criminal networks” linked to people smuggling and seized 1,900 boats over the same period.
The number of people fleeing war or poverty in Africa, the Middle East and Asia who cross to the European Union has dropped to about 80,000 this year from more than a million in 2015, according to the IOM.