The man was among the migrants who climbed over two barbed wire fences and appeared to have died of a heart attack, they said in a statement.
“Unfortunately, one of the migrants died… it seems from a cardio-pulmonary arrest,” the statement added.
Another 100 migrants from the sub-Saharan region had failed in the attempt to enter Melilla, the statement said. Three migrants were hurt in the incident, it said, without elaborating.
The border between Melilla and Morocco is protected by two parallel fences standing six metres high and topped with barbed wire.
In June, the Socialist government of Pedro Sanchez said it intended to remove the barbed wire but has so far not done so.
In late August, the Spanish authorities sent about 100 migrants who had entered Ceuta — a second Spanish enclave in Morocco — back across the border, sparking an outcry from human rights groups.