WASHINGTON (Reuters) - The U.S. House of Representatives on Wednesday passed a $1.2 trillion spending bill to fund the government through September and avoid federal agency shutdowns on Saturday when existing money is depleted.

FILE PHOTO: The dome of the U.S. Capitol is seen in Washington September 25, 2012. REUTERS/Kevin Lamarque/File photo

With the 309-118 vote in the Republican-controlled chamber, the legislation now goes to the Senate, which is expected to pass it before a midnight Friday deadline.

The Pentagon is a big winner in the legislation, with defense spending rising significantly.

While the bill cleared the House easily, dozens more Democrats voted for it than Republicans, many of whom oppose most spending measures.

This was the first major legislation to pass the House this year with bipartisan support and marks Republican President Donald Trump’s first legislative victory, even though he railed against some of its provisions.

The legislation bulks up federal funding for border security but does not pay for starting construction on a U.S.-Mexico border wall that Trump promised to keep out illegal immigrants and drugs.

Trump had said he would make Mexico pay for the wall, but the Mexican government refused, making it necessary for the new administration to ask Congress for the money.

Democrats and many Republicans have argued that a wall is an ineffective and wasteful way of securing the southern border.

Another battle over the barrier is expected when Congress tries to pass a spending bill for the fiscal year starting Oct. 1.

Trump already has begun focusing on that upcoming fight. In a tweet on Tuesday, he taunted lawmakers, saying, “Our country needs a good ‘shutdown’ in September to fix mess!”

The legislation would add $12.5 billion this fiscal year for the Pentagon, with another $2.5 billion available after Trump gives details on his plans for defeating the Islamic State militant group.

It ignores many of the spending cuts on domestic programs the White House had sought and adds $2 billion for the National Institutes of Health, $295 million for Puerto Rico’s underfunded Medicaid healthcare for the poor and $407 million to fight fires in Western states.

But the legislation is late in coming. The fiscal year began last Oct. 1 and for the last seven months federal agencies have been operating mainly on simple extensions of the previous year’s funding and the priorities that came with that.