President Barack Obama and congressional leaders reached a last-minute budget deal on Friday, averting a government shutdown.

With a midnight deadline looming for a government closure, the compromise between the Democrats and Republicans requires lawmakers to approve stopgap funding to keep federal agencies running into next week until the budget agreement can be formally enacted.

The plan calls for $39 billion in spending cuts. There was no immediate comment from the White House or congressional Democrats.

A shutdown would have idled hundreds of thousands of workers and carry political risks for Obama and his fellow Democrats as well as opposition Republicans, who would be seen by voters as failing to make compromises.

Leaders of the House and Senate were at odds on Friday over the reasons for not reaching agreement.

Democrats said they were at odds over federal funding for birth control. Republicans said spending cuts were the issue.

After narrowing their differences, the House was set to vote later on Friday night on a short-term funding bill to keep the government running until the longer budget plan can be enacted into law.

Without an agreement, money to operate the federal government for the next six months would run out at midnight on Friday and agencies such as the Internal Revenue Service would begin a partial shutdown.

Despite the apparent resolution of the impasse, the bitter political fight raised questions about the ability of Obama and a divided U.S. Congress to deal with bigger issues looming down the road, from raising the federal debt ceiling to reining in budget deficits, as the 2012 presidential election campaign gathers steam.

The leadership of the world's lone remaining superpower has been consumed for days by the budgetary infighting that could bring large swathes of government to a standstill.