But the police continued with a crackdown on gay people, even during the coronavirus lockdown. At least 17 people have been arrested so far this year, said Ms. Darwish, the researcher, some by officers using dating apps.
Another source of danger is the medical profession, she added. Some psychiatrists prescribe discredited forms of therapy in an effort to “cure” people of their homosexuality, she said. In one recent case, a psychiatric institution tried to induce that effect by administering electric shocks to a man while showing him gay pornography.
In Canada, Ms. Hegazi found safety but limited relief.
She was devastated by the death of her mother, who died from cancer soon after her daughter reached Canada, and Ms. Hegazi felt helpless to be unable to return to Egypt to be with her siblings.
Haunted by her ordeal in Egypt, she said she suffered anxiety and panic attacks. She began to stutter. “I try to avoid talking about prison,” she wrote. “I lose the ability to leave my room.”
“She never got past her mother’s death,” said Mr. Fouad, her lawyer. “She couldn’t find like-minded friends. She was angry about everything that had been done to her. She wanted so badly to come back but she was afraid she would be arrested.”
Twice before, she had attempted suicide.
Since her death on Saturday, some reaction has suggested that not much has changed in Egypt since she left two years ago. “This is what atheism does to a person,” read one comment on the website of the Youm7 newspaper. “You become selfish, you commit homosexuality and adultery, and then kill yourself. Chaos in the name of freedom.”
But for many others, Ms. Hegazi’s words rang louder.
Among the tributes paid to her on Monday was a short performance by Hamed Sinno, the lead singer of Mashrou’ Leila. On Instagram, he posted a photo of Ms. Hegazi smiling as she gripped a pair of tickets for his concert, then he sang a couplet Ms. Hegazi posted before her death:
The sky is more beautiful than the earth.
And I want the sky, not the earth.
Nada Rashwan contributed reporting.