Democrats in the House have criticised the involvement of Musk in the process, who they pointed out is an unelected billionaire.
Musk, who Trump has tasked with cutting government spending in his future administration, had lobbied heavily against an earlier version of the bill.
During the debate, Republicans said they looked forward to a "new era" with Trump taking office on 20 January and Republicans in control of both chambers of Congress. Currently, the Senate remains under Democratic control.
The budget wrangling left Republican House Speaker Mike Johnson bruised as he faced criticism from members of his own party over his handling of the process.
"We are grateful that everyone stood together to do the right thing and having gotten this done now as the last order of business for the year, we are set up for a big and important new start in January," Johnson told reporters after Friday's vote.
He also said that he had spoken frequently to both Trump and Musk during the negotiations.
Johnson's remarks came shortly after Musk praised the Louisiana congressman's work on the budget in a post on X, the social media platform he owns.
"The Speaker did a good job here, given the circumstances," he posted. "It went from a bill that weighed pounds to a bill that weighed ounces."
The dramatic budget fight served as a preview of the tense legislative fights that could be in store.