WASHINGTON — After years of delays and contentious negotiations that threatened to derail the farm bill, Congress completed its work on a new five-year package Tuesday that now heads to the president.

The Senate voted 68-32 on a $500 billion farm bill that will end direct payments to farmers, expand the popular crop insurance program and cut spending on food stamps for some poor Americans by 1%.

The White House announced Tuesday afternoon that Obama is going to sign the farm bill on Friday during a visit to East Lansing, Mich.

The bill, which had been mired in Congress for nearly three years, was passed in a dizzying blur of action. It took just over a week for the legislation to be introduced by House and Senate negotiators and approved by lawmakers in both chambers. The House passed the bill by a 251-166 vote last week.

"We've arrived at a farm bill that works for all of America. This bill will strengthen agriculture for years to come," said Sen. Debbie Stabenow, D-Mich., chairwoman of the Senate Agriculture Committee. "It's time to get it to the president for signature."

The nearly 1,000-page bill, which replaces the 2008 legislation, sets policy on everything from trade and conservation to food stamps and subsidy payments to farmers. An estimated 16 million Americans are employed because of agriculture and food industries.

The legislation will reduce spending by $23 billion over a decade, with a portion coming from the end of the direct payment subsidy program that gives out $5 billion annually to farmers regardless of need. In its place, the farm bill uses some of the savings to expand the federally subsidized crop insurance programs by $5.7 billion to help farmers better manage risk tied to unexpected weather disasters or gyrations in commodity prices.

The farm bill also saves $6 billion by reducing the number of conservation programs to 13 from 23. Funding for food stamps, known as the Supplemental Nutrition Assistance Program, will be trimmed by $8 billion over the next decade, about 1% of total spending. The cuts are made through changes to a heating assistance program used by some states to determine whether an individual qualifies to receive food assistance. Ten states would be used to develop employment and training test programs for food stamp recipients.

The change to the food stamp program that serves some 47.5 million Americans would reduce food stamp benefits by $90 a month for about 850,000 people. Until recently, the food stamp program was the subject of the most haggling among Democrats and Republicans, as the two sides disagreed on how steep the cuts should be. House GOP leaders nearly killed the farm bill last July when they temporarily split the farm policy measures from the nutrition provisions before rejoining them later. Food stamps make up about 80% of spending in the farm bill.

While the reduction in the food stamp program is far below the $40 billion the Republican-controlled House had been looking for, it's still above the $4.5 billion targeted by the Democratic-led Senate.

The sweeping bill failed to include changes to country of origin labeling that shows where animals were born, raised and slaughtered. U.S. meat packers have said the 2002 law violates free trade provisions and has saddled them with extra costs that could be passed on to consumers. Even after the World Trade Organization criticized the rule in June 2012, prompting the USDA to make changes, the livestock industry has said the requirements remain unwieldy.

A controversial amendment from Rep. Steve King, R-Iowa, that was approved initially by the House last year also was stripped out of the final bill. It would have prohibited states from enacting laws that set standards for the production of agricultural goods that are sold within its own borders, but are produced in other states. The amendment was intended to block a California law that requires eggs sold in the state to come from chickens raised in cages where birds have enough room to spread their wings.

Agriculture groups said while the farm legislation passed by Congress wasn't perfect, they were relieved that the arduous process to craft a new law was coming to an end.

"Farmers are pretty agile and willing to do whatever it takes to make it work, they just need to know what the rules are," said Doug Sombke, president of the South Dakota Farmers Union."It's probably one of the hardest things I've ever had to work for is this farm bill. We've had difficulties in the past with farm bills but never like this one. I just hope we never have to come to this point again."