A spokeswoman for Walt Disney Parks and Resorts, Jacquee Wahler, said, “As we have said all along, this lawsuit was completely baseless, and we are gratified by the decision.”

The former workers’ cases hinged on their argument that the companies had violated clauses of the visa law requiring employers to show that hiring H-1B workers “will not adversely affect the working conditions” of other workers in similar jobs. The law also requires large outsourcing companies that employ many H-1B workers to certify in some circumstances that those workers “will not displace any similarly employed U.S. worker” within six months of applying for the visa.

The outsourcing companies argued that the law would apply to them only if the American workers who were displaced by visa holders they hired had originally been their employees, not Disney’s. Judge Presnell was persuaded by that argument, although he did not entirely reject the idea that the Americans were “adversely affected” by being fired.

The decision was a broad victory for Disney and its contractors, but Judge Presnell left the former workers a small window to amend their lawsuits and to try again.

Mr. Perrero said the decision was a dismaying surprise. “This has become an effective business model in the IT industry where two companies can come together and wipe out American jobs without much fear of legal action,” he said. “I just hope that greed isn’t taking our country in the wrong direction.”