WASHINGTON — The Democrat-led House passed legislation on Tuesday to grant a path to citizenship to about 2.5 million immigrants whose legal protections President Trump has moved to end, advancing a measure that highlights the bitter partisan differences over immigration.

The bill, which passed 237 to 187, with seven Republicans voting yes, would create a new legal pathway for young undocumented immigrants brought to the United States illegally as children, known as Dreamers, and for those with Temporary Protected Status, granted to immigrants whose countries are ravaged by natural disaster or violence. It is almost certain to die in the Republican-led Senate, where there is no appetite to challenge Mr. Trump on his signature issue and the majority regards it as amnesty for people who have broken the law.

The White House said on Monday that Mr. Trump would veto the measure. But as the vote tally hit 218, representing a majority for passage, scores of Dreamers seated in the House gallery rose to their feet and cheered loudly, chanting, “Si se puede!” and then the English translation, “Yes we can!” It was evidence of the national grass-roots movement they have built over more than a decade to push for permanent legal status.

The Democrats’ immigration measure was notable both for what it did and for what it did not do. It was a grant of legal status for a narrow group of immigrants, not a comprehensive measure to overhaul what lawmakers in both parties concede is a badly broken immigration system and to deal with the 11 million undocumented immigrants living in the United States. Such a measure passed the Senate in 2013 only to die in a Republican-controlled House.