(CNN) In 2017, Sarah Hegazi was arrested and said she was tortured for waving a rainbow gay pride flag at a concert in Cairo. Last weekend, the 30-year-old died by suicide in Canada.
Hegazi's friends reported her death, circulated a suicide note and shared an outpouring of messages of solidarity, grief and anger. Their mourning was soon hijacked by hateful messages.
On social media, posts about Hegazi that ended with the traditional condolences, "May God Have Mercy on her," were followed by comments saying "she is not worthy of His Mercy," and a torrent of expletives targeting her sexuality.
These bitter exchanges echoed a long-running clash between Egyptian progressives and conservatives that haunted Hegazi's life. She was a software developer, a "feminist, interested in politics and a queer activist," fellow LGBTQ activist and friend Malak Elkashif told CNN from Cairo.
By waving the flag, Hegazi became an icon for the gay community and a target for state violence.
Analysts say that Egypt's government often enforces conservative values by imprisoning, torturing and silencing women, members of the LGBTQ community and other citizens who don't conform to its social norms.
Earlier this year, Egypt told the UN Human Rights Council it has "vowed to safeguard human rights, ensuring equal rights and opportunities to all citizens without discrimination," and it has "thoroughly" investigated all "individual" cases of torture.
After conservatives criticized and filed complaints against two women for posting dancing and lip synching videos on TikTok that got hundreds of thousands of views, authorities last week charged them with the vaguely worded crime of "violating family principles and values."
"The regime uses its tools -- such as the media, and mosques -- to tell Egyptian society, which is understood to be 'religious by nature': We too protect religion and social morality, so there is no need for Islamists to compete with us!" Hegazi wrote in an article published by local independent platform Mada Masr in 2018.
The Egyptian state and the proponents of political Islam had put aside their long-running animosity, agreeing on using hate and prejudice to curb individual freedoms, she argued. Her writings weaved political critique into her struggle as an openly gay woman.
When Hegazi and her friends raised the rainbow flag at the September 2017 concert by Mashrou' Leila, a Lebanese band with an openly gay frontman, she was hailed by allies for "breaking many barriers of silence," said her friend Tarek Salama.
"To see someone who publicly say they are leftist, that they are against state violence and that they are queer, made me worried about her. But I was also fascinated and humbled," Salama told CNN.
Photos of the colorful flag fluttering under the spotlights enraged talk show hosts and newspaper columnists. Days later, Hegazi and her friends were arrested. Police ultimately detained at least 75 people in the month following the concert in what one Egyptian rights group called an "unprecedented upsurge in security crackdown targeting gay and transgender citizens or those believed to be so."
Sixteen years prior, in 2001, a similar crackdown took place. In what was known as the Queen Boat case, police arrested dozens of men in Cairo and charged them with "habitual debauchery" -- a legal term used to prosecute LGBTQ people. The men hid their faces during the public trial in fear of recognition, and reported a life ruined by the torture, shame and stigma.
What set Hegazi's experience apart was her willingness to show her face despite the backlash.
"It was a day to mark in history as the start of the liberation of the LGBTQ community in Egypt," Elkashif said.
Hegazi remained in detention for three months. She said she was tortured by electrocution and subjected to sexual harassment by female prisoners acting on the orders of officers "who believed she had to be punished," she wrote on Daaarb.com, an electronic publication of the Socialist Popular Alliance Party.
Egyptian authorities have repeatedly denied claims of systematic torture in prisons and did not respond to Hegazi's claims. The government didn't immediately respond to CNN's request for comment.
During interrogation at the state security prosecution, which usually handles terrorism and high profile political cases, Hegazi would clutch her lawyers' arms and beg them not to let her go back to detention, her lawyer and friend Mostafa Fouad told CNN. In hours of questioning, police probed into the details of her life, she later wrote. They asked her why she took off the Islamic headscarf, which she had previously donned, and if she was a virgin.
She was charged with "promoting debauchery" and with joining an illegal organization that "threatens public and societal peace," a charge usually leveled against Islamists and political dissidents, according to Fouad.
Hegazi was released pending trial to find that her family and her neighbors had rejected her and she was fired from her job. Society "welcomed" what happened to her, she wrote in Daaarb.com last March.
"The Egyptian middle class leans towards the socially and religiously conservative right. It supports state decisions to impose guardianship on the society ... they practice social stigma [against anyone who] revolts against this oppressive patriarchal culture that is based on oppressing women, workers, and religious and sexual minorities," Hegazi wrote.
"It is the loudest class in society, so exposing and criticizing it is a duty."
Her words would prove prescient in explaining her life's struggle and the unsympathetic reaction to her death. "[The middle class] laid the foundation for hate, psychological and physical violence, sexual harassment and bullying," she added.
Hegazi traveled to Canada months after her release, but never seemed to escape what had happened.
"Sarah left Egypt two years ago, but Egypt and its trauma didn't leave her alone," her friend Salama wrote on Facebook.
Though asylum in Canada provided safety from prison, it was taxing in other ways. Her mother died of cancer shortly after she left and her inability to be close to her and her younger siblings at the time took a toll on her, she said.
She said she suffered from depression, post-traumatic stress disorder, panic attacks and loneliness. The electroconvulsive therapy she underwent in Cairo and Toronto caused memory loss, she wrote in Mada Masr in 2018. She stuttered, was terrified and attempted suicide twice.
Her writing, activism and support of friends facing depression and arrest continued. Her Instagram account includes posts urging patience with those battling PTSD, along with posts in solidarity with political causes from Black Lives Matter, to imprisoned friends in Egypt and the millions trapped by conflict in Idlib, Syria.
"She was strong, she could have survived this, but society destroyed her," Fouad recounted from his self-exile in Turkey. "She talked me off suicide four times before," he said, breaking down in tears.
After her death, online trolls and commenters said her advocacy for LGBTQ rights was a greater crime than her "sinful sexuality."
"Sarah committed a crime against religion and society by supporting homosexuality and publicizing her homosexuality and atheism," one user wrote on Facebook.
Others used expletives and derogatory terms while arguing that she would be denied God's mercy and rot in hell. In Egypt's Twittersphere, her name was trending along with "People of Lot," a reference to a Quranic passage about punishment for homosexuality.
"The most humiliating and infuriating part in her death are those gloating in it," her friend Amr Mohamed said in a video posted on Facebook. Addressing these people, he added, "She died after detention, torture and expulsion ... what religion that would reward you for insulting a dead person?"
A day before her death, Hegazi posted a picture of herself lying on green grass under a bright blue sky. "The sky is more beautiful than earth, and I want the sky, not earth," she wrote. Hamed Sinno, Mashrou' Leila's lead singer, put these words to music in a video tribute.
"Her blood is on my hands as much as it is on yours. It should have been me in that prison cell. I apologize if I gave anyone hope that they'll one day see us as human," he wrote on Facebook, also from self-exile.
After her death, an older, familiar photo went viral -- the one of Hegazi wrapped in the rainbow flag, as she was perched on a friend's shoulders, her smile beaming over the crowd at the band's concert in 2017.
Sinno posted the picture, writing: "Freedom to your soul."
In the note she wrote before her death, she said: "To my siblings, I tried to survive and I failed. Forgive me. To my friends, experiences have been cruel and I'm too weak to resist. Forgive me. To the world, you have been extremely cruel, but I forgive."
How to get help: In the US, call the National Suicide Prevention Lifeline at 1-800-273-8255. The International Association for Suicide Prevention and Befrienders Worldwide also can provide contact information for crisis centers around the world.