President Donald Trump speaks at the Major County Sheriffs and Major Cities Chiefs Association Joint Conference in Washington, Wednesday, Feb. 13, 2019. Credit: Susan Walsh | AP

WASHINGTON — The Senate passed a massive budget and border security deal Thursday to avert another government shutdown after President Donald Trump committed to signing the legislation but said he’d also declare a national emergency to build a wall along the U.S.-Mexico border.

The $333 billion bill passed 83-16 and is expected to pass the House later Thursday to avoid a shutdown that would begin Saturday. Maine’s two senators — Republican Susan Collins and independent Angus King — backed the bill, but they and the rest of the state’s delegation opposed the emergency move.

The Senate vote followed drama in the Senate as Majority Leader Mitch McConnell, R-Kentucky, appeared suddenly on the floor to end hours of uncertainty, announcing that Trump had agreed to support the bill.

At the same time, McConnell told senators that Trump would be declaring a national emergency to circumvent Congress and get more money for his wall — and that McConnell would support the move, even though he’s been outspoken in opposition to an emergency declaration. The legislation provides a fraction of the $5.7 billion Trump has sought for his border wall.

After getting burned by Trump in December on a spending bill the Senate passed and the president disavowed, McConnell wanted to move as fast as possible to a vote following Trump’s assurance of support. The majority leader was in such a hurry to announce Trump’s backing and call the vote that he interrupted Republican Sen. Chuck Grassley of Iowa in the middle of a speech about biofuels, drawing wrathful exclamations and glares from Grassley.

Even as Democrats welcomed passage of the compromise legislation, they denounced Trump’s plans to declare a national emergency to get more money for his wall than Congress has agreed to.

House Speaker Nancy Pelosi, D-California, accused the president of making an “end-run around Congress” and warned that a future Democratic president could do the same thing on gun-control issues.

Collins said in a Thursday statement that Trump’s emergency declaration would be a “mistake” of “dubious constitutionality” that would be challenged in court. King, who caucuses with Democrats, said in a statement it is “antithetical to our American system of government.”

Maine’s two Democratic U.S. representatives also harshly criticized the move, with Chellie Pingree of the 1st District calling it an “abuse of power,” and Jared Golden of the 2nd District said lawmakers “should fix our immigration system and strengthen our borders with bipartisan deals like the compromise bill we’re voting on today.”

The House could pass a disapproval resolution to overturn the emergency declaration, and McConnell would be forced to put it on the Senate floor, an outcome the majority leader had hoped to avoid. McConnell had cautioned Trump privately about the scenario.

The 1,159-page legislation would fund nine Cabinet departments and dozens of other agencies through Sept. 30, removing — for now — the threat of another government shutdown and political brinkmanship over Trump’s demands for his wall.

The compromise would provide $1.375 billion for 55 miles of new fences along the border in Texas, far short of the $5.7 billion Trump had sought for 234 miles of steel walls. The final number for border barriers is also less than deals that were on the table last year before Trump pushed the government into a record-long 35-day shutdown in an attempt to get all the wall money he wants.

The legislation was released just before midnight Wednesday, giving lawmakers and the White House little time to review it before it’s put to a vote. Lawmakers defended the rushed timeline because of the impending deadline they face Friday night at midnight, when funding would expire for the Homeland Security Department and other agencies comprising about a quarter of the federal government — unless Congress and Trump act first.

White House officials have kept their precise plans closely held for weeks, insisting that they had legal ways to secure more than $5.7 billion in funds without congressional approval but refusing to say exactly how they’d do it.

The White House’s goal for weeks has been to build more than 230 miles of wall along the Mexico border, and Congress approved roughly one-quarter of that in the new agreement. It’s unclear whether Trump will try to secure the remainder of it through executive orders, try for a more narrower plan or attempt to do more than he has asked for in the past.

A central promise of Trump’s 2016 presidential campaign was that he would somehow make Mexico pay for the construction of the border wall, but since becoming president, all of his efforts have focused on using U.S. taxpayer money to finance the projects. Trump has said that a pending revised trade agreement with Mexico and Canada effectively fulfills his promise, but it is unclear whether Congress will approve that trade agreement. And there is no language in that trade agreement that would create a new funding mechanism to create money for a wall.

BDN staff writer Michael Shepherd and the Washington Post’s John Wagner, Mike DeBonis, Sean Sullivan and Paul Kane contributed to this report.