The House easily cleared the bill, 268-151, despite complaints from many Democrats that Republicans had rushed the measure unnecessarily. The Senate overwhelmingly passed the legislation a day earlier.
A White House spokesman said President Barack Obama would sign the measure if Congress approved it before he leaves office.
The bill grants a one-time exception for Mattis from the law that bars former service members who have been out of uniform for less than seven years from holding the top Pentagon job. The restriction is meant to preserve civilian control of the military. Mattis, 66, retired from the Marine Corps in 2013.
Rep Adam Smith of Washington, the top Democrat on the House Armed Services Committee, said the panel held no substantive hearings to examine the impact of the legislation.
More From This Section
He also faulted Republicans for not pushing back when the Trump transition team refused to allow Mattis to testify before the panel Thursday afternoon after he had completed his confirmation hearing in the Senate.
"We are being treated as irrelevant," Smith said. Rep Mac Thornberry of Texas, the committee's top Republican, blamed the transition team for "short-sightedness." But he rejected Smith's assessment.
"The fact is unless we pass this bill today we are not able to have a secretary of defense on Jan. 20," Thornberry said. The House will not be in session next week.
The Senate passed the legislation by an 81-17 vote with 30 Democrats backing the bill. The legislation is separate from a Senate confirmation vote on Mattis. But the strong bipartisan support signals there are no real hurdles to approving Trump's choice for defense secretary.