Congress approved legislation Friday that allows retired Marine Gen. James Mattis to run the Pentagon in the Trump administration.

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.

Congress last granted an exception to the law in 1950 for George Marshall, a former five-star Army general and secretary of state.

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. 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.

"We're not irrelevant because if we do not vote for this legislation, (Mattis) does not serve," Thornberry said.

He also said that passing the bill before President-elect Donald Trump is sworn in ensures a seamless transition at the Pentagon at a time when the United States faces an array of threats.

"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.

During a military career than lasted four decades, Mattis served in numerous senior military positions, including commander of U.S. Central Command in charge of all American forces in the Middle East.