WASHINGTON — Retired Gen. James Mattis appeared headed for confirmation as defense secretary after he told a Senate panel yesterday that Russia is the nation’s “principal threat” and promised to always give “frank advice” to President-elect Donald Trump.

To clear his path, Congress stood on the verge of approving a waiver of the requirement that Mattis, 66, who retired as a Marine general three years ago, must have been a civilian for at least seven years before serving as defense secretary.

Sen. Kirsten Gillibrand (D-N.Y.) praised Mattis for his service but also led the Senate opposition to the waiver, calling it a “historic mistake” that will set a bad precedent for future defense secretaries and the constitutional principle of civilian control of the military.

“I truly believe we are about to unwind something that has so served this country well for the past 50 years,” Gillibrand said. “The last time the country unwound it, they said never again.”

That exception to the 1947 law was for retired Gen. George C. Marshall in 1950.

Sen. John McCain (R-Ariz.), the Armed Services Committee chairman, called opponents of the waiver “uninformed” and sought to assuage the concerns of Sen. Jack Reed of Delaware, the committee’s top Democrat, by saying that “this is a one-time deal.”

The Senate voted 81-17 for the waiver after the Senate Armed Services Committee approved it at the end of Mattis’ three-hour confirmation hearing. The House Armed Services Committee voted 34-28 to bypass the law. A full House vote was expected yesterday or today.

Get the Breaking News newsletter! Get the latest breaking news as it happens. By clicking Sign up, you agree to our privacy policy.

Gillibrand voted against it. Senate Minority Leader Chuck Schumer (D-N.Y.) voted for it.

Mattis still must win committee approval and a Senate confirmation vote.

Mattis has support from Republicans and most Democrats, who say they hope he can provide a check on Trump and some of his unorthodox statements chiding NATO, warming to Russia and approving of nuclear proliferation.

At his hearing, Mattis, a four-star general whose last post was as commander of the U.S. Central Command, downplayed Trump’s comments.

Asked often about Russia, Mattis called it “an adversary in areas,” and accused Russian leader Vladimir Putin of trying to “break” NATO. But he also said the United States should try to engage and work with Putin, as Trump has advocated.

Mattis said the U.S. military needs to be rebuilt and strengthened. He said that he favored giving Israel a military edge over other countries in the Middle East but also said he supported a two-state solution with Palestinians to bring peace.

His toughest grilling came from Gillibrand, who asked him whether he planned to roll back policies permitting women and gays to serve in the military. He had called their service a bad idea in remarks he made in 2014 and 2015, she reminded him.

“I was not in a position to go back into government when I made those statements,” Mattis responded. He said he doesn’t plan to change any policies unless “someone brings me a problem.”

Gillibrand also questioned his view of the gulf between civilians and soldiers. She quoted him as saying, “We fear that an uninformed public is permitting political leaders to impose an accretion of social conventions that are diminishing the combat power of our military, disregarding our practitioners’ advice.”

Mattis said, “Senator, my belief is that we have to stay focused on a military that is so lethal that on a battlefield it will be the enemy’s longest day and their worst day.” But he added he believes “military service is a touchstone for patriots, of whatever stripe.”