WASHINGTON — The House has passed legislation to overturn President Barack Obama’s immigration actions and remove protections for immigrants brought illegally to the country as children.

The measures were part of a $39.7 billion spending bill for the Department of Homeland Security. The vote was 236-191.

The legislation faces tough prospects in the Senate and a veto threat from the president. But Republicans said they had to act against what they described as an unconstitutional overreach by Obama.

The legislation would roll back executive actions Obama announced in November to extend temporary stays of deportation to around 4 million immigrants in the country illegally. It also would undo an earlier program that provided work permits and deportation protections to more than 600,000 immigrants who arrived illegally in the country as children.

U.S. Rep. Bruce Poliquin, R-Maine, wrote he voted for the spending bill, “because it will help put an end to the President’s dangerous and unlawful unilateral action on immigration.”