WASHINGTON (Reuters) - The U.S. House of Representatives passed the farm bill on Wednesday, capping months of acrimonious debate to finalize the legislation funding the nation’s $867 billion food and agriculture programs.

FILE PHOTO: A farmer drives tractor along a road in Pearl City, Illinois, U.S., July 25, 2018. REUTERS/Joshua Lott/File Photo

The bill, which passed by a vote of 369 to 47, will be submitted to President Donald Trump for his signature into law following its approval in the U.S. Senate on Tuesday.

The final agreement on the bill came after Republicans in the lame duck Congress walked back some of their demands, including a proposal to tighten criteria for receiving food stamps that had been championed by Trump. Democrats will take control of the House in January.

Some provisions regarding forestry management, backed by Trump’s Agriculture and Interior Secretaries have also been largely excluded from the final legislation.

“While I feel there were missed opportunities in forest management and in improving work requirements for certain SNAP recipients, this bill does include several helpful provisions,” Agriculture Secretary Sonny Perdue said in a statement, referring to the Supplemental Nutrition Assistance Program.

“I commend Congress for bringing the farm bill across the finish line and am encouraging President Trump to sign it.”

Passage of the bill has been hailed in a largely bipartisan manner as it provides some financial certainty for farmers, a key Trump constituency that has been hurt by the U.S. trade war with China, a key buyer of U.S. soy beans and other farm produce.

On Tuesday Trump, who had previously accused Democrats of stalling the bill, said the progress on it was bipartisan and that “farmers were well taken care of.”

More than 40 million Americans, or about 12 percent of the U.S. population, depend on the SNAP food stamps program to keep from going hungry.

The Republican-led move to tighten eligibility for food stamps triggered a bitter partisan debate, delaying the bill beyond the most recent version’s expiration in September. It was finalized only after Democrats won a majority in the House of Representatives in the November elections.