Morocco, claiming centuries-old rights over the territory rich in phosphates, fisheries and possibly offshore oil, annexed it after former colonial power Spain withdrew in 1975.
The Polisario Front launched a low-level guerrilla war against Morocco's armed forces to back its claim for an independent state. The two sides have been observing a UN-sponsored ceasefire since 1991.
"No single prisoner held because of the territory's dispute will be left behind bars. Forty-eight, all of what remained of the prisoners, were pardoned by the king," a senior government official said on Saturday.
The pardoned detainees were jailed late last year for between 10 months and five years for anti-Moroccan riots in Laayoune, the main town in Western Sahara. They were sentenced for offences including sabotage of public property and using weapons against public officials.

"The pardon by his Majesty King Mohammed underlines that the situation in the territory and in Morocco in general was changing towards a better future of reconciliation, democracy and prosperity," said Khali Henna Ould Errachid, chairman of the Royal Consultative Council for Sahara Affairs.
"The decision to free the remaining prisoners was meant to signal that we had begun together moving to cement our full reconciliation."
"All the pardoned prisoners will be released later today," a senior government official said.
The king pardoned 216 Sahrawi prisoners last month after a six-day visit to the territory where he vowed Western Sahara would remain part of Morocco.