WASHINGTON—The Senate passed a $1.3 trillion spending bill early Friday, acting to avert a government shutdown with less than 24 hours to spare and bringing to a close a messy negotiating process over the sprawling measure.

The bill, which now goes to President Donald Trump for his signature, would lift military spending by $80 billion this year and domestic programs by $63 billion, a decision lauded by defense hawks and criticized by lawmakers frustrated by its impact on the deficit. White House officials said Thursday that...