The Senate has approved a waiver that would allow retired Gen. James Mattis to serve as secretary of defense, granting a rare exception to a law meant that requires military veterans to have been out of uniform for at least seven years before taking the top job at the Pentagon.

On Thursday afternoon, lawmakers voted 81 to 17, overwhelmingly approving the waiver on the same day Mattis testified before the Senate Armed Services Committee.

Mattis sailed through his confirmation hearing Thursday morning, even as he broke with President-elect Donald Trump on Russia and Iran . Challenges posed by the relationships with both nations promise to pose consume much of Mattis' time, if he is confirmed.

Following questioning, the committee took up, and easily approved, the waiver on a 24-3 vote. Democrats Kirsten Gillibrand of New York, Richard Blumenthal of Connecticut and Elizabeth Warren of Massachusetts voted against it.

The House Armed Services Committee approved the waiver Thursday afternoon, sending it to the full chamber for a vote.

Mattis retired from the Marines in 2013 after more than four decades, and without the waiver would not be eligible to serve as secretary of defense. A World War II-era law bars ex-military members from the top Pentagon job within seven years of retiring from service, an effort to ensure civilian control of the armed services. Congress has provided a waiver just once, to allow the appointment of George Marshall in 1950, with legislation that expressed the sense of Congress that "no additional appointments of military men to that office shall be approved."

Some Democrats opposed the language of the waiver because it did not explicitly name Mattis. And in the House, lawmakers in both parties were concerned that the Trump transition refused to allow Mattis to testify before the House Armed Services Committee, reversing an earlier decision to allow him to do so.

"The transition team told me last night that they would not allow him to come and testify, even though we have been communicating with them since December and even though Mattis himself is enthusiastic to come testify," Armed Services Chairman Mac Thornberry, R-Texas, told Politico on Wednesday.

"I'm disappointed. I think it's a mistake," he said. "This is a big issue – it hadn't come up in 67 years – it deserves a hearing."