The House passed a government spending package on Wednesday, meaning the U.S. will avoid a government shutdown as long as President Donald Trump signs it into law.

The measures passed by a margin of 361 to 61.

Though the president raised the possibility of vetoing the legislation in recent weeks, he said "we're going to keep the government open" hours before Wednesday's vote. The Senate already passed the spending legislation and funding lapses at 12:01 a.m. ET on Monday.

Trump slammed the spending package because it did not include money for his proposed border wall. Republican congressional leaders opposed a shutdown because it could hurt GOP candidates only six weeks before midterm elections, when the party will defend its majorities in both the House and Senate.

Republicans plan to address funding for the proposed barrier on the U.S.-Mexico border after the Nov. 6 contests. Democrats are favored to take a House majority, while Republicans are frontrunners to keep the Senate.

The spending package that passed Wednesday funds the Defense Department and a few other pieces of the government, while allotting money for the remainder of the government in a short-term package. Republicans in part hoped an uptick in military spending would assuage the president's doubts about border security money.

Last week, Trump called the bill "ridiculous" and urged Republicans to "GET TOUGH!"

Trump tweet

Earlier this month, he said he would consider shutting down the government "because I think it's a great political issue." He threatened to veto another funding package over border wall money earlier this year, but eventually signed it.