CAIRO — The last days of the government of Hosni Mubarak and the turbulent revolution that followed were tense, occasionally gut-wrenching times for many in Egypt. But for gay and transgender Egyptians, it was also a period of unaccustomed freedom.

They socialized in bars and sidewalk cafes and met partners over cellphone dating apps with a greater degree of openness and comfort than they had known.

But that era came to an abrupt end with the return of military rule.

Since the 2013 military intervention that established former Gen. Abdel Fattah el-Sisi as the country’s ruler, at least 250 lesbian, gay, bisexual and transgender people have been arrested in a quiet crackdown that has shattered what had been an increasingly vibrant and visible community. Through a campaign of online surveillance and entrapment, arrests and the closing of gay-friendly businesses, the police have driven gay and transgender people back underground and, in many cases, out of the country.

Before the crackdown, “there was no deliberate campaign of arrest and monitoring,” said Dalia Abdel Hameed, a researcher at the Egyptian Initiative for Personal Rights. “But now the police are going out of their way to arrest gay men and trans women.”