Now their cover has been blown in a way that would be criminal in most Western societies, rights advocates say. Yet they have no legal recourse.
"Forcibly outing people is not just an obvious violation of their right to privacy," said Ahmed Benchemsi, communications director for the Middle East and North Africa division of Human Rights Watch. "When wrapped in incitement to hate and calls to violence based on sexual orientation, it's also a crime.
"A legal system respectful of universal rights would empower victims to press charges," he said. "But in Morocco, same-sex behavior is also criminalised, so victims could find themselves trapped in a tragic catch-22 situation."
What makes this episode particularly painful, gay leaders say, is that it was ignited by someone who had also been singled out.
On April 13, a Moroccan transgender Instagram personality based in Istanbul, Naoufal Moussa or Sofia Talouni, was insulted about her sexual orientation. In a rage, she released a profanity-laced video encouraging women to download location-based meeting apps, like Grindr and Planet Romeo, which are usually used by gay men.
In subsequent videos, she said her aim was to reveal the hypocrisy of Moroccan society by showing her attackers how many gay men were living in their vicinity, perhaps even in their own homes.
Many people followed Moussa's lead and created fake accounts on the apps to gather photos of gay men, which they then posted on private and public Facebook pages, setting off the homophobic attacks.
The attacks ignited a firestorm of criticism, both of Moussa and of Morocco's discriminatory laws.
Adam Eli, founder of the New York-based activist group Voices4, worked in coordination with Moroccan LGBTQ rights activists to get Moussa's Instagram account deleted.
"For now the account has been suspended, and already a new one has popped up," he said. "We did not solve the issue of queer-phobia in Morocco. However, we showed a bunch of young queer people, who are scared and in quarantine, that they are not alone, that they have the force of the international queer community behind them."
A spokesperson for Facebook, which owns Instagram, confirmed that Moussa's account had been suspended.
"We don't allow people to out members of the LGBTQ+ community because it puts them at risk," the spokesperson wrote in an email. "We've disabled Naoufal Moussa's Facebook and Instagram accounts, and we're taking proactive steps to find and remove other content like this."
What seems to have set Moussa off was a late-night conversation with a little-known Instagram user, who in an interview asked to be identified only as Yassine, for fear for his safety.
Moussa has attained a measure of fame in recent months, using her platform to talk crudely about sex and to entertain her followers in an insolent and confrontational manner in vulgar Moroccan Arabic. That has made her an object of fascination and horror to her more than half-million followers.
And she is known to despise LGBTQ people who do not make their sexual orientation known.
Yassine, a 22-year-old, said he was initially delighted to be picked to go live on Instagram with Moussa. But what felt like an honor rapidly turned into embarrassment and shock as Moussa compelled him to acknowledge that he was gay, threatening to post revealing photos showing him with another gay man. It is unclear how she obtained the photos.
"I was shocked and then very scared," Yassine said. "She destroyed my life."
He has since been forced to move out of the house of a family member and to use his savings to rent a small apartment in Tangier.
"Everybody is sending the video and saying bad things about me," he said. "My mom, also, she's very sad. She's not talking to me anymore. My friends at the gym, friends I went to school with — they all blocked me."
Many who saw the outing of Yassine were outraged and attacked Moussa, flagging her account to Instagram. That's when she got angry and suggested downloading gay meeting apps, which led to the outburst of anti-gay violence.
"My dating life in Morocco was somehow OK, as long as my partner and I were being super discreet and cautious," said one gay man who asked to be identified only by his initials, N.A., and says his family hasn't seen the photos.
He has been staying with his grandmother and waiting in fear for something bad to happen.
Abdellah Taia, a prominent gay author and one of few to publicly declare his sexual orientation in Morocco, says that the state keeps people in a gray area, making them vulnerable to abuse and discrimination and forcing many into hiding.
"This is a great and bitter Moroccan comedy," he said, adding of the pandemic that is exacerbating the situation: "Corona reveals every day a little more how the weakest on this Earth are even weaker and more ostracised than we thought. It's sad. It's tragic. It's revolting."
Morocco's Interior Ministry did not respond to a request for comment.
The outing episode is seen by many as destroying a fragile balance that the country's underground gay culture has built laboriously, made even worse in a time of uncertainty and economic hardship. But they do have some support at home.
Nadia Bezad, president of the Pan-African Organisation for the Fight Against Aids, said that while Morocco's laws were unlikely to change, its health ministry encourages associations like hers to help vulnerable populations, including gay people.
"They can come to us without any danger or apprehension," she said. "The reality is that they are tolerated but expected to remain invisible."
Written by: Aida Alami
© 2020 THE NEW YORK TIMES