Washington: US Senate leaders said Wednesday they had reached a bipartisan budget deal for 2018 and 2019—a move which, if approved by Congress, would avert a second government shutdown in just three weeks.

The deal, months in the making, was seen as a major achievement for both the ruling Republicans and opposition Democrats in a deeply divided Washington.

The breakthrough came on the eve of a midnight Thursday deadline for Congress to pass a stopgap spending measure—its fifth since October—or once again turn the lights out on the federal government.

The proposal would lift caps on federal spending that were mandated under a 2011 law, boosting military and non-military funding by some $300 billion in total, aides said.

“The compromise we’ve reached will ensure that, for the first time in years, our armed forces will have more of the resources they need to keep America safe," Senate majority leader Mitch McConnell said on the Senate floor.

Republican Senator Lindsey Graham, a defence hawk, said it was the “best news for the military... since 2011."

The agreement would also ensure funding for domestic priorities pushed by Democrats including disaster relief, health centres and fighting a surging opioid epidemic.

“The budget deal doesn’t have everything Democrats want, it doesn’t have everything the Republicans want, but it has a great deal of what the American people want," top Senate Democrat Chuck Schumer told his colleagues.

The deal raises the debt ceiling until March 2019, postponing a potential fiery clash within President Donald Trump’s own Republican Party, and essentially clears the decks for Congress to address other thorny issues such as immigration and infrastructure.

Before the deal was announced, the House passed a partisan bill that would fund government for six weeks and the military through the remainder of fiscal year 2018.

The Senate is now expected to rewrite that measure, pass it and send it back for House approval before Thursday’s funding deadline—provided there are no efforts to slow the process in the Senate.

McConnell and Schumer said the deal was the product of extensive negotiations between both parties and the White House, which reacted positively to developments on Capitol Hill.

“We’re certainly happy with the direction that it’s moving," press secretary Sarah Sanders said, adding that the White House would need to see the final components.

That was a turnaround from Tuesday, when Trump had said he would “love" a shutdown if he did not get his way on immigration.

Several Senate Democrats, including John Tester of Montana, said they were buoyed by the deal but wanted to study the details before signing on.

House speaker Paul Ryan urged all House members to support the deal, saying it breaks the “logjam" on public priorities and “will ensure that America’s armed forces have more of the resources they need to keep America safe."

In a statement, he also said the agreement includes investments in infrastructure and resources to combat the opioid crisis, as well as nearly $90 billion in disaster relief for hurricane-stricken Puerto Rico, Florida, Texas and the US Virgin Islands.

But the compromise could face stiff blowback in the lower chamber of Congress, where fiscal conservatives may balk at adding $300 billion to the national debt just months after passing a $1.5 trillion tax cut package.

But liberal stalwarts might also revolt, over the sensitive issue of immigration and the fate of millions of undocumented migrants.

Immigration is not part of the compromise. Instead, McConnell will allow an open debate on possible immigration solutions on the Senate floor, beginning as early as next week—a promise he made to end a three-day shutdown last month.

Democrats have long pursued a strategy to link the federal funding debate to a solution for hundreds of thousands of “Dreamer" immigrants who were brought to the country illegally as children.

Top House Democrat Nancy Pelosi highlighted the approach Wednesday with an extraordinary day-long address—the Chamber’s longest in more than a century—to her House colleagues in which she read dozens of testimonials from “Dreamers" and called on Ryan to take action on immigration.

“Our Dreamers hang in limbo, with a cruel cloud of fear and uncertainty above them," Pelosi said.

“The Republican moral cowardice must end."

The Dreamers were shielded from deportation under the Obama-era program called Deferred Action for Childhood Arrivals (Daca). But Trump ended the program last September, and set 5 March as a deadline for resolving the issue.

The White House plan—which would put 1.8 million immigrants on a path to citizenship, boost border security, and dramatically curtail legal immigration—has been panned by Democrats. A series of bipartisan efforts have stalled.