A federal judge in Virginia has ordered the U.S. Air Force to halt efforts to discharge service members who are HIV-positive.

U.S. District Judge Leonie Brinkema issued the preliminary injunction on Friday. She ruled that the Air Force's treatment of HIV-positive personnel is "irrational, inconsistent, and at variance with modern science."

The ruling will keep at least two HIV-positive men in the Air Force for the time being. They were just days and weeks away from being formally discharged.

The Morning Rundown Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The case, Roe and Voe v. Shanahan, was filed by Lambda Legal and OutServe-SLDN, two LGBTQ rights organizations. They argued that the Pentagon uses “discriminatory deployment policies” that stop people living with HIV from deploying outside the U.S. without a waiver.

“This is a major victory in our fight to ensure everyone living with HIV can serve their country without discrimination,” Scott Schoettes, an attorney with Lambda Legal, said in a statement. “These decisions should be based on science, not stigma, as today’s ruling from the bench demonstrates."

Schoettes said the government relied on outdated scientific material in the court proceedings, while Lambda and OutServe-SLDN relied on more current scientific data that show HIV is a manageable chronic condition easily controlled by medication.

Peter Perkowski, the legal and policy director of OutServe-SLDN, said his organization also applauded Judge Brinkema's decision.

"Judge Brinkema recognized not just that the military’s policies were harming our members who are living and serving with HIV,” he said in a statement, "but also indicated that, at least on the evidence before her, the military’s decisions were based on outdated medical science and are categorically denying people living with HIV the same opportunities as their fellow service members. We look forward to a final decision in the case.”

An official from the Department of Defense said the agency does "not comment on pending litigation."

FOLLOW NBC OUT ON TWITTER, FACEBOOK & INSTAGRAM