America's "don't ask, don't tell" policy, which bans gay men and women from serving openly in the US military, suffered a potentially crippling blow tonight after a federal judge ordered a halt to its enforcement.

The move, which could bypass political deadlock on the measure in Washington, sprang from a court case brought by a Republican gay rights group – the Log Cabin Republicans.

US district court Judge Virginia Phillips ordered an immediate worldwide injunction on the 17-year ban after hearing lengthy arguments in the case, which was first brought in Riverside in southern California in 2004.

Gay rights groups hailed the decision as historic, putting an end to a practice that they say is both prejudiced towards gay people and harmful to the military, as it kicks out experienced soldiers at a time of numerous conflicts around the world. "The order represents a complete and total victory for the Log Cabin Republicans, and reaffirms the constitutional rights of gays and lesbians in the military for fighting and dying for our country," said Dan Woods, a lawyer for the Log Cabin organisation.

But the reality is not quite as simple as that. The US Department of Justice now has 60 days to appeal the decision to issue the injunction. The Obama administration has insisted it wants to get rid of the ban – but only after Congress has voted on it.

Yet getting a vote through Congress to overturn the policy might not be easy. An attempt earlier this year – when a measure ending "don't ask, don't tell" was tacked onto a defence bill – ended up being defeated in the Senate.

Gay rights groups say that the White House should now let Phillips's judgment and injunction stand, and thus allow a legal decision to get around the policy deadlock. If the department elects not to appeal the decision then it will effectively become law, they say.

"The president has said this law harms our national security, and we believe it would be a mistake to appeal the decision. Each additional day that this unjust law remains in force is one more day the federal government is complicit in discrimination," said Joe Solmonese, president of the Human Rights Campaign, which fights for gay equality.

But so far justice department lawyers are keeping mum on their future plans when it comes to a potential appeal. Tracy Schmaler, a spokesman for the Department of Justice, told the Associated Press that the federal government was reviewing the ruling and had no further immediate comment.

"Don't ask, don't tell" has been a source of complaint from gay rights campaigners ever since it was brought in by President Clinton in 1993. It allows any soldier who admits to being gay or is caught engaging in homosexual activity to be discharged from the army. Those opposed to the law say it discriminates on the basis of sexual orientation in a way that would not be tolerable if it instead covered a soldier's ethnicity or gender.

Upholding the ban remains popular among many politicians and generals, especially Republicans and conservatives. Former Republican presidential candidate John McCain has spoken out strongly in favour of maintaining the ban.

Judge Phillips's ruling is good news for gay rights groups at a time when anti-gay crimes have dominated US headlines this week. They include several beatings in New York – one in the Stonewall bar which gave the modern gay rights movement its name.

At the same time, several politicians have made anti-gay statements as they campaign for November's bitterly contested midterm elections. Comments by top Republicans like New York state governor candidate Carl Paladino, and South Carolina senator James DeMint have been particularly egregious. Both have said that they do not feel gay people should be allowed to teach in schools.