Congress passed legislation to avoid another government shutdown Thursday, moving to prevent one crisis even as the fight over President Donald Trump's proposed border wall escalated.

The GOP-controlled Senate easily cleared the bill, which included only about a quarter of the money Trump sought for border barriers, by an 83-16 margin. The Democratic-held House approved the measure comfortably in a 300-128 vote.

The president plans to sign the proposal and declare a national emergency in an attempt to fund the wall. His expected executive action would in part try to appease conservatives who argued he should oppose the plan because it does not meet his demand for $5.7 billion to construct barriers.

The legislation would keep the government running through Sept. 30. Lawmakers and Trump have until midnight Friday to fund nine departments and prevent the second partial closure since December.

If the proposal becomes law, 800,000 federal workers bludgeoned by the last 35-day shutdown would avoid even more financial pain. It will not end the fight over Trump's proposed border wall, as legal battles over the emergency declaration will likely erupt.

The president has said he is "not thrilled" with the spending legislation. It would allocate $1.375 billion for 55 miles of bollard fencing, much less than the $5.7 billion Trump wanted for a wall. The proposal also authorizes funds for more border security agents, customs officers, immigration judges, and technology to detect drugs and weapons.

Outside of the Department of Homeland Security, it includes provisions such as a 1.9 percent pay raise for federal employees, a $1 billion increase in U.S. Census spending and $17 billion for transportation infrastructure improvements.

Eleven Republicans and five Democrats in the Senate opposed the legislation. Four of the five Democratic senators who voted against it — Cory Booker of New Jersey, Kirsten Gillibrand of New York, Kamala Harris of California and Elizabeth Warren of Massachusetts — are running to challenge Trump for the presidency next year.

While House leaders from both parties backed the legislation, both the majority Democrats and particularly minority Republicans saw defections.

Trump has spent recent days attempting to explain his apparent defeat in Congress on border wall funding. The president has argued for weeks that he can use money from other agencies to build the barrier.

"Regardless of Wall money, it is being built as we speak!" Trump tweeted Tuesday.

The potential national emergency declaration has divided Republicans. Several GOP senators argued it would set a bad precedent.

Pelosi said she "may" file a legal challenge and would review her options. She also warned Republicans that a future Democratic president could declare a national emergency over other issues such as gun violence.

Some Democratic House members also floated a vote on a resolution to disapprove of Trump's likely national emergency declaration. It is unclear if party leaders would support it.

Trump repeatedly cast an emergency declaration as a choice rather than a necessity, which could potentially weaken his legal case for it.

Subscribe to CNBC on YouTube.

WATCH: The government shutdown faces mounting lawsuits, including over 'involuntary servitude'