Five years ago, while speaking in New York, Iranian President Mahmoud Ahmadinejad infamously declared that there are no homosexuals in his country. But for at least 15 years, the regime has quietly been offering gay Iranians exemptions from mandatory military service.

Those exemptions, however, often come with costs, and gay-rights activists say that a considerable number of male homosexuals are fleeing Iran rather than living with the stigma attached to being gay in the Islamic Republic. According to the Iranian Railroad for Queer Refugees (IRQR), a Toronto-based human-rights group, 118 Iranian queer asylum seekers requested its help last year—the highest number of cases the organization has ever seen in one year.

Yousef, a gay Iranian who asked to be identified only by his first name out of fear of repercussions, is one such asylum seeker. Ten months ago, he left for neighboring Turkey because his life in Iran became too difficult since he was let out of military service.

“What could I tell my parents?” Yousef told The Daily Beast in a telephone interview. “How could I explain the reason I was released from the military?”

He hadn’t intended to quit his military service, which is compulsory for Iranian men over 18. In 2007, he started his two-year stint in the southeastern Iranian city of Khash, but soon other soldiers began to bully him over the way he carried himself and spoke.

“They teased me to the point where I had to go to the base psychologist,” the 29-year-old said. “He told me, ‘You are different,’ and asked if I was a homosexual.”

Yousef said yes. He felt safe being there with the doctor and worried his harassment could grow worse, as some gay Iranians have reported being beaten and raped during their military experience. The doctor sent Yousef to several hospitals, where he was examined then released from his service.

Iran’s military regulations permit exemptions from the military on various grounds, including “behavioral disorders” and “moral and sexual deviations.”

Human-rights observers say this clause has allowed hundreds of Iranians to request exemptions on the basis of being gay or transgender.

Coming out in Iran, however, can put homosexuals in serious danger. Gay Iranians have reported being detained, beaten, and lashed up to 100 times. They can also be sentenced to death under the country’s Islamic Penal Code, which is based on Sharia.

Iran has one of the highest numbers of recorded executions of any country in the world, according to Amnesty International. It’s difficult, however, to determine how many victims have been executed for homosexuality or sodomy.

For Iranians who speak out about their homosexuality, getting classified as unfit for military service is often a long and harrowing process, according to the Arsham Parsi, the IRQR's executive director.

Sometimes it involves a physical exam. “Some doctors have very stupid tests from the 19th century,” he said. “Then the doctor signs a document and sends the person to a special medical group, which sometimes insults him. For example, they say, ‘Take off all your clothes and prove you’re incapable of having sexual relationships with women.’ They think if someone is gay or transgender, their sexual organs are disabled and they can find this out through medical examinations. This is harassment.”

Other times, doctors will perform degrading mental evaluations. “Sometimes they ask you if you prefer ‘top’ or ‘bottom,’” said Hossein Alizadeh, Middle East and North Africa coordinator at the International Gay & Lesbian Human Rights Commission.

The insinuation, he said, is that “if you’re on top in a sexual relationship, you’re probably man enough to still serve in the military, but if you’re on the bottom, we’ll have to let you go.”

The harassment continues, Parsi said, even after gay Iranians are granted exemption. Several of them recently told his organization they received letters from Iran’s judiciary, pressuring them to have surgery to change their gender—a process that is allowed by the Islamic regime.

It’s hard to know the exact number of gay Iranians who have been exempted from the military. But one Tehran psychiatrist said the number of homosexuals seeking exemptions through his private clinic has grown in recent years, with an average of 12 applications a month.

“We know their language, and we understand if this person is really [gay] or not,” the doctor said. “The men who visit here come with their heads held high and say, ‘I’m gay.’ But we have a criterion called ‘visibility,’ which is how visible they are to their families. Most of their families don’t know.”

Homosexuality is a taboo in Iranian society, and gays like Yousef try to hide their sexual orientation from their families and friends. This became tougher for Yousef, though, once he received his military exemption card and saw that it was marked with “Article 33, paragraph 8.” This corresponds with the military regulation that allows gay and transgender Iranians to get out of the service.

“I wanted to work at a magazine, but I couldn’t because of what was written on my card,” he said. Because of similar problems, he believes, many gay Iranians are too afraid to ask for military exemptions. “Otherwise,” he said, “the numbers would be higher.”

Sam, a 29-year-old who received his exemption after in-depth psychiatric interviews, said he was required to bring his father with him. “Until then, my father didn’t know I was gay,” he said. “I had to tell him. It was very difficult.”

Why these exemptions exist is a matter of debate. Some like Sam, who praised the policy, said it encourages gay emigration. “I believe they want us to quietly get our passports and leave the country,” he said.

Alizadeh, however, disagreed. “They want to exclude you by saying you’re not macho enough to serve in the military,” he said. “It has been a nice way for gay people not to join a harsh situation, but the truth is that the laws are written by people who are concerned not about sexual rights but about the protection of Islamic morals in the Army. So they decided that ‘gay bottoms’ are the biggest threat to the Army and we have to let them go.”

Either way, emigration is the end result for some gay Iranians. Sam left Iran in 2011 and moved to Canada earlier this year.

“I miss my family,” he said, “but not Iran, my homeland. There was no hope for me there.”