A Moroccan man jailed for pretending to be the brother of the king on the social networking site Facebook has been given a royal pardon.
Protesters in Rabat had been calling for Fouad Mourtada's release
Fouad Mourtada's lawyer said his client had left the Casablanca jail where he was serving his three-year sentence.
He had been arrested at the beginning of February for "usurping the identity of Prince Moulay Rachid".
Mr Mourtada had insisted his internet entry was a bit of fun, and a campaign was launched in his support.
Mr Mortada's brother Ilyas told the BBC that Fouad was in good health, and was delighted to be free.
His lawyer said Mr Mourtada was still trying to come to terms with what had happened to him.
His release has delighted Moroccan human rights organisation, international pressure groups and internet users around the world who had campaigned for his release.
The king granted the pardon just before the anniversary of the birth of the prophet Mohammed, a public holiday in Morocco, and a date on which pardons are often announced.
But the BBC's James Copnall in Rabat says the case shows that the royal family remains a taboo subject in Morocco.
He says Moroccan journalists and others have learnt that harsh words about the king, or Islam, or Morocco itself, can lead to trouble.
The journalist and editor Ahmed Benchemsi faces up to five years in jail over an article he wrote about a speech made by King Mohammed VI.
His trial has been adjourned until September.
The Islamist leader Nadia Yassine is also facing trial for saying she is in favour of Morocco becoming a republic.
The Moroccan establishment is keen to stress the progress it has made in opening up the country, particularly since Mohammed VI came to the throne nearly 10 years ago.
Mr Benchemsi is accused of criticising the king
Under his father, Hassan II, Morocco had an appalling human rights record.
Political opponents and human rights activists, among many others, faced terrible conditions in Moroccan jails, often merely for objecting out loud.
But while most people agree society is more open now, Moroccans know the king and the royal family remain almost untouchable.
King Mohammed VI is regarded as a descendent of the Prophet Muhammad, and to question his authority is seen as a challenge to his religious role as the Commander of the Faithful.