Chafik Lafrid, 33, says he ocassionally dresses in women's clothes.

Chafik Lafrid's life has become a nightmare since footage of his arrest in Marrakesh on New Year's Eve, wearing a dress and a wig, went viral on social media.

Homosexuality is illegal in Morocco, and the 33-year-old, who occasionally dresses in women's clothes, had until that night kept secret the fact that he is gay. Until that is, he was detained after a minor traffic accident.

Mistreated by the police and then attacked online, he said he now wants to emigrate as he fears for his safety.

"I had an image of Morocco as a country that respects difference," he said bitterly. "What happened changed my mind."

Footage of his arrest has been seen millions of times online: handcuffed, barefoot and wearing a short blue dress, he is escorted by police as a crowd of onlookers film and insult him.

The police do nothing to intervene.

Minutes earlier, Lafrid, an administrator at a private medical clinic, had been returning home from a party in Morocco's tourist capital.

He was driving along a busy avenue when a scooter slammed into his car.

A police officer arrived at the scene and ordered him to step out of the vehicle, but Lafrid refused -- wearing a lace dress, a curly, long wig and makeup, he was afraid of how the crowd of onlookers might react.

"The policeman broke the window with his baton and forced me out of the car," he said. "He took off my wig, dragged me to the ground and handcuffed me."

Images go viral

A journalist for a Marrekesh news website, who was accompanying the police patrol, filmed the scene.

At the police station, officers took his photo, checked his identity and questioned him about the accident. He was then released.

The rider of the scooter sustained minor injuries but did not press charges, and Lafrid faces no further legal action over the incident.

But the next day, images of his arrest, the photos taken by the police and his personal documents went viral on social media.

Lafrid, interviewed in the capital Rabat because he did not want to be filmed in his home city, said he now fears for his safety.

"My address has been published on the Internet, any fundamentalist could come and try to harm me," he said.

He said his relationship with his parents, who had no idea about his secret life, was been destroyed, and he feels "humiliated" and "in shock".

After consulting a psychiatrist, he was granted a month's sick leave for depression.

His boss, colleagues and patients at the clinic where he works have sent messages of support.

But since the night of the accident, he has been living "in fear of being recognised", he said.

He wears men's clothes and dons a baseball cap to make his face less visible.

And Lafrid has sought help from a local campaign group, the Alternative Movement for Individual Freedoms (MALI).

Ibtissam Lachgar, the movement's joint coordinator, said Lafrid's experience reflects the homophobia in Moroccan society and in the state.

"The state's representatives that night reflected that homophobia," Lachgar said, a rainbow flag on the wall behind her.

Society torn

The Moroccan police have sanctioned four Marrakesh officers for "breach of professional obligations" over the leaking of Lafrid's identity.

Moroccan society remains torn between religious conservatism and modernity, and while LGBT people there live in less fear than in other parts of the region, they are still targeted by authorities.

Official figures show that in 2017, 197 people were prosecuted under Article 489 of the Moroccan penal code, which bans same-sex relations and imposes penalties if convicted of between six months to three years imprisonment.

"Every day, we receive testimonies from LGBT people who have been attacked," Lachgar said.

"Quite a number of them want to seek asylum (outside Morocco), and many have already left."

She called on the state to scrap Article 489 and do "real substantive work to allow a change of mentality".

But for Lafrid, that would be too little, too late.

He told AFP he wants to leave Morocco and move to a country "where everybody's individual choices are respected".