WASHINGTON — The Senate and house resoundingly approved a border security compromise Thursday that ignores most of President Donald Trump’s demands for building a wall with Mexico but would prevent a new government shutdown. The White House said Trump would sign it but then declare a national emergency and perhaps invoke other executive powers to try to shift money to the wall from elsewhere in the federal budget.

Democratic leaders Nancy Pelosi and Chuck Schumer branded such a presidential declaration “a lawless act, a gross abuse of the power of the presidency and a desperate attempt to distract from the fact that President Trump broke his core promise to have Mexico pay for his wall.”

House passage and Trump’s signature were assured for the basic spending bill compromise, which for now would stamp a bipartisan coda on a nasty melee that has dominated the initial months of power sharing in Washington.

The specter of the national emergency declaration has produced widespread opposition in Congress, but Trump is under pressure to soothe his conservative base and avoid looking as if he has surrendered in his wall battle with Congress.

At the White House, press secretary Sarah Sanders said Trump would sign the bill and take “other executive action, including a national emergency.” She added, “The president is once again delivering on his promise to build the wall, protect the border and secure our great country.”

Trump had demanded $5.7 billion to start building more than 200 miles of wall. The bipartisan agreement provides under $1.4 billion — enough for 55 miles of new barriers and fencing.

An emergency declaration and other assertions of executive power to access money are expected to prompt lawsuits and potential votes in Congress aimed at blocking Trump from diverting money, which could conceivably reach billions of dollars. White House aides and congressional Republicans have suggested that Trump might tap funds targeted for military construction, disaster relief and counter-drug efforts.

Senate Majority Leader Mitch McConnell said he would support Trump’s emergency declaration. That was a turnabout for the Kentucky Republican, who like Democrats and many Republicans, has until now opposed such action.

Democratic opponents of a declaration have said there is no crisis at the border and Trump is merely sidestepping Congress, while Republicans have warned that future Democratic presidents could use the move to force spending on their own priorities like gun control.

But lawmakers from both parties were relieved to forestall a fresh federal shutdown and put the border security battle — at least this phase of it — behind them.

Meeting with reporters, House Speaker Pelosi warned that legal action aimed at blocking Trump’s emergency declaration was an option, but she stopped short of saying it would definitely occur.

No. 2 House Democratic leader Steny Hoyer, was more definitive. “House Democrats will challenge this irresponsible declaration,” he said in a statement.

The Senate approved the border security deal 83-16.

The House passed the measure Thursday night, 300-128.

Trump’s signature will end this stage of a raucous legislative saga that commenced before Christmas. The low point was the 35-day partial federal shutdown, which Trump sparked and was in full force when Democrats took control of the House, compelling him to share power for the first time.

Trump yielded on the shutdown Jan. 25 after public opinion turned against him and congressional Republicans.

He did not win a nickel of the $5.7 billion he had demanded for his wall but caused missed paychecks for legions of federal workers and contractors and lost government services for countless others. It was a political fiasco for Trump and an early triumph for Pelosi.

The fight left both parties dead set against another shutdown. That sentiment weakened Trump’s hand and fueled the bipartisan deal, a pact that contrasts with the parties’ raging differences over health care, taxes and investigations of the president.

Notably, the word “wall” — which fueled many a chant at Trump campaign events and then his rallies as president — does not appear once in the compromise’s 1,768 pages of legislation and explanatory materials. “Barriers” and “fencing” are the nouns of choice.

The pact would also squeeze funding for Immigration and Customs Enforcement, or ICE, in an attempt to pressure the agency to gradually detain fewer immigrants. To the dismay of Democrats, it would still leave an agency many of them consider abusive holding thousands more immigrants than it did last year.

The measure contains money for improved surveillance equipment, more customs agents and humanitarian aid for detained immigrants.

The overall bill also provides $330 billion to finance dozens of federal programs for the rest of the year, one-fourth of federal agency budgets.