Immigrant families walk to a respite center after they were processed and released by U.S. Customs and Border Protection, June 27, 2018, in McAllen, Texas.
Immigrant families walk to a respite center after they were processed and released by U.S. Customs and Border Protection, June 27, 2018, in McAllen, Texas.

The U.S. House of Representatives on Wednesday overwhelmingly rejected a sweeping overhaul of the country's immigration policies, ignoring a last-minute appeal from President Donald Trump to approve the legislation.

The vote was 301-121, with solid Democratic opposition and a splintered Republican vote.

Republican leaders supported passage. But many of the majority bloc's most conservative lawmakers opposed the bill because they said it would create a path to citizenship for several hundred thousand young immigrants already living in the U.S. who years ago were brought illegally to the country by their parents, a provision opponents said amounts to "amnesty" for lawbreakers.

WATCH: Immigration vote

?The defeat of the legislation sets the stage for consideration in the coming days of a much narrower measure designed to put into law Trump's decision last week to halt separation of children from their parents when they have been apprehended by U.S. agents as they cross illegally from Mexico into the United States.

Last week, Trump said fellow Republicans in Congress "should stop wasting their time" considering immigration proposals until after congressional elections in November, in hopes of electing more Republicans. But in a new Twitter remark, Trump said he thought there was political gain for House Republicans to approve the wide-ranging bill. 

In a tweet using all capital letters, Trump called the measure "strong but fair," even though he said Senate Democrats "won't let it pass." But Trump said that "passage will show that we want strong borders & security while the Dems want open borders = crime. Win!"

The House last week rejected tougher immigration controls, at which point Trump suggested lawmakers abandon their efforts to pass any immigration proposal.

The U.S. is holding more than 2,000 children who were separated from their parents in recent weeks, but has been slow in reuniting them with their parents in the days after Trump, in the biggest policy reversal of his 17-month presidency, ended the breakup of families at the border.

On Tuesday, in a case brought by the American Civil Liberties Union, U.S. District Judge Dana Sabraw ordered the government to return children under the age of five to their parents in the next 14 days and other minor children within 30 days.

Protesters carry signs and chant slogans in front
FILE - Protesters carry signs and chant slogans in front of the federal courthouse in Los Angeles, June 26, 2018.

The Justice Department said the order "makes it even more imperative" that Congress pass legislation to give border agents the ability "to simultaneously enforce the law and keep families together."

Otherwise, "lawlessness at the border will continue," the Justice Department contended.

Sabraw, appointed to the bench by Republican President George W. Bush, sharply criticized the Trump administration's handling of parent-children separations.

"Measures were not in place to provide for communication between governmental agencies responsible for detaining parents and those responsible for housing children, or to provide for ready communication between separated parents and children," he said. "There was no reunification plan in place."

Demonstrators block a bus with migrant children on
FILE - Demonstrators block a bus with migrant children on board, during a protest outside the U.S. Border Patrol Central Processing Center, in McAllen, Texas, June 23, 2018.

In addition to ordering that the children be reunited, Sabraw said the government should take all necessary steps to facilitate regular communication between parents and children detained in separate facilities, and that parents cannot be deported without their children.

Attorney General Jeff Sessions, speaking at an event Tuesday in Los Angeles, defended the administration's immigration policies as necessary for safety and security.

"This immigration question is a decisive issue for our time. As the president often says, a country without borders is not a country," Sessions said. "I don't know why that's so hard for some people to understand. In the United States, we have the most generous immigration laws in the world."