WASHINGTON — The House of Representatives on Wednesday passed a bill authorizing nearly $1 trillion in spending on farm subsidies and nutrition programs, setting the stage for final passage of a new five-year farm bill that has been stalled for more than two years.

Negotiators from the House and Senate spent several weeks working out their differences on issues in the legislation, including cuts to food stamps, income caps on farm subsidies and a price support program for dairy farmers. The bill is expected to save about $16.6 billion over the next 10 years.

The bill passed the House by a vote of 251 to 166. The Senate is expected to take up the bill later this week.

Compared with earlier, more contentious votes on the farm bill, Wednesday’s vote was largely bipartisan. Many Democrats who had opposed it because of cuts to the food stamp program supported it on Wednesday. A number of Republicans, including many who wanted deeper cuts to the food stamps, also voted for passage.