The Republican-led House has rejected a far-ranging immigration bill despite its eleventh-hour endorsement by President Donald Trump, as the gulf between the party's moderate and conservative wings proved too deep.

The vote was 301-121, with nearly half of Republicans opposing the measure. The depth of opposition was an embarrassing showing for Mr Trump and a rebuff of House GOP leaders, who'd postponed the vote twice and proposed changes in hopes of driving up the vote for a measure that seemed doomed from the start.

The tally also seemed to empower Republican conservatives on the fraught issue. Last week a more conservative package was defeated, although 193 Republicans voted for it — just 20 votes short of passing.

Even if the most recent attempt passed, however, it would have been dead on arrival in the closely divided Senate, where Democrats would have had enough votes to kill it.

Mr Trump released a tweet early Wednesday morning in support of the comprehensive bill, writing in all caps, “HOUSE REPUBLICANS SHOULD PASS THE STRONG BUT FAIR IMMIGRATION BILL.” The administration then released a formal statement of support as well.

Congress will now be forced to focus on much more narrow legislation preventing the separation of families at the border.

Nearly 2,000 children remain separated from their parents since Mr Trump’s Justice Department began implementing its “zero tolerance” policy along the US-Mexico border earlier this year. A federal judge in California ordered a halt to the majority of family separations on Tuesday.

The judge also ordered for the reunification of families impacted by the policy and mandated that every child held in detention centers is able to speak with their parents within 10 days.

Announcing her order halting the policy, US District Court Judge Dana Sabraw wrote, “Plaintiffs have demonstrated a likelihood of success on the merits, irreparable harm, and that the balance of equities and the public interest weigh in their favor, thus warranting issuance of a preliminary injunction."

‘Families belong together’ protests over Trump immigration policy Show all 8 1 /8 ‘Families belong together’ protests over Trump immigration policy ‘Families belong together’ protests over Trump immigration policy Mishawaka, Indiana AP ‘Families belong together’ protests over Trump immigration policy Washington DC AFP/Getty Images ‘Families belong together’ protests over Trump immigration policy New York Mayor Bill De Blasio speaks in Tornillo, Texas alongside the many other US mayors who have called for detained immigrant children to be reunited with their families AP ‘Families belong together’ protests over Trump immigration policy Albuquerque Mayor Tim Kelle leaves a teddy bear as a gift for detained immigrant children in Tornillo, Texas AP ‘Families belong together’ protests over Trump immigration policy Seattle Mayor Jenny Durkan and Los Angeles Mayor Eric Garcetti leave sandals as gifts for detained immigrant children in Tornillo, Texas AP ‘Families belong together’ protests over Trump immigration policy San Diego, California EPA ‘Families belong together’ protests over Trump immigration policy US embassy, Mexico City AFP/Getty Images ‘Families belong together’ protests over Trump immigration policy San Diego, California EPA

However, the decision does not throw out other components of Mr Trump’s zero tolerance policy, like criminally prosecuting all immigrants crossing the border — including those legally seeking asylum.

“This Order does not implicate the Government's discretionary authority to enforce immigration or other criminal laws, including its decisions to release or detain class members,” the judge wrote. ”Rather, the Order addresses only the circumstances under which the Government may separate class members from their children, as well as the reunification of class members who are returned to immigration custody upon completion of any criminal proceedings.”