The U.S. Senate narrowly averted a partial government shutdown Friday, as the chamber approved spending legislation for several government agencies just hours before current funding was due to expire.

Senators voted 75-22 to approve a $467.5 billion spending package that will fund agriculture, transportation, housing, energy, veterans and other programs through the end of the fiscal year on September 30. The package headed to President Joe Biden to be signed into law.

Funding for those programs was due to expire at midnight.

The vote partly resolved a bitter, monthslong battle over government spending that at one point left the Republican-controlled House of Representatives leaderless for three weeks.

“To folks who worry that divided government means nothing ever gets done, this bipartisan package says otherwise,” Senate Democratic leader Chuck Schumer said ahead of the vote.

The package easily passed the Republican-controlled House of Representatives earlier this week. But action in the Senate was delayed as some conservative Republicans pressed for votes on immigration and other topics. They all failed.

Congress must still work out a deal on a much larger package of spending bills, covering the military, homeland security, health care and other services. Funding for those programs expires on March 22.

Taken together, the two packages would cost $1.66 trillion. Some Republicans had pushed for deeper spending cuts to tame a $34.5 trillion national debt.

All these measures were supposed to have been enacted into law by last October 1, the start of the 2024 fiscal year. While Congress rarely meets that deadline, the debate this year has been unusually chaotic. Congress so far has had to approve four temporary funding bills to keep agency operations continuing at their previous year’s levels.

The spending bills include $241.3 million in earmarks — local projects secured by individual lawmakers — requested by Democratic Senator Dianne Feinstein. She died on September 29, 2023, two days before the start of the fiscal year.