The AMDH human rights group said the 12 migrants would be jailed for three years without parole after being prosecuted for "illegal entry onto Moroccan soil" and "violence against law enforcement officers".
"It's a very harsh and unexpected sentence, given that they had initially been sentenced to 11 months in prison," said Omar Naji of AMDH in the border town of Nador.
Around 2,000 people, many of them Sudanese, stormed the frontier on June 24 in an attempt to reach Spanish territory across one of the European Union's two land borders with Africa.
Rights groups have accused both Moroccan and Spanish security forces of responding with excessive force, leaving at least 23 migrants dead, the worst toll in years of such attempted crossings.
The June 24 tragedy followed days of clashes between Moroccan security forces in a forest near Melilla where migrants often spend months living rough before attempting to cross the heavily fortified barrier.
Naji said the 12 had been arrested in one of the clashes, six days before the border incident.
Since the tragedy, Morocco has sentenced dozens of migrants to prison terms of up to two and a half years on charges including illegal entry and belonging to criminal gangs.
The Spanish enclaves of Melilla and Ceuta have long been a magnet for people fleeing violence and poverty across Africa to seek refuge in Europe.