WASHINGTON—The House voted to block the White House from redirecting federal funds toward building a border wall, and the Senate inched closer to doing the same, raising the specter of President Trump exercising his veto power for the first time.

As newly empowered House Democrats moved to assert congressional authority over government spending, there appeared to be nearly enough Republican support for the measure to clear the Senate in the coming weeks. Mr. Trump has already said he would veto the measure should Congress...