WASHINGTON — Matt Gaetz on Thursday withdrew as President-elect Donald Trump’s pick for attorney general amid continued fallout over a federal sex trafficking investigation that cast doubt on his ability to be confirmed as the nation’s chief federal law enforcement officer.

The announcement averts what was shaping up to be a pitched confirmation fight that would have tested how far Senate Republicans were willing to go to support Trump’s Cabinet picks. It represents a setback in Trump’s efforts to install fierce loyalists in his administration and is the first indication of the resistance the incoming president could face within his own party to picks with checkered backgrounds.

“While the momentum was strong, it is clear that my confirmation was unfairly becoming a distraction to the critical work of the Trump/Vance Transition,” said Gaetz, a Florida Republican who a day earlier met with senators in an effort to win their support for confirmation to lead the Justice Department.

“There is no time to waste on a needlessly protracted Washington scuffle, thus I’ll be withdrawing my name from consideration to serve as Attorney General. Trump’s DOJ must be in place and ready on Day 1,” he added.

Trump, in a social media post, said: “I greatly appreciate the recent efforts of Matt Gaetz in seeking approval to be Attorney General. He was doing very well but, at the same time, did not want to be a distraction for the Administration, for which he has much respect. Matt has a wonderful future, and I look forward to watching all of the great things he will do!”

Trump did not immediately announce a new selection.

The choice of Gaetz just nine days ago to lead the department that once investigated him came even as Trump was thought to be considering other contenders with more extensive legal qualifications. In the Senate, deeply skeptical senators repeatedly raised concerns over the sex trafficking allegations and demanded more information about a now-closed federal investigation. Meanwhile, Justice Department lawyers were taken aback by the pick of a partisan lawmaker who has repeatedly railed against their agency and echoed Trump in claiming that it had been weaponized against political adversaries of Democrats.

In recent days, an attorney for two women said his clients told House Ethics Committee investigators that Gaetz paid them for sex on multiple occasions beginning in 2017, when Gaetz was a Florida congressman.

One of the women testified she saw Gaetz having sex with a 17-year-old at a party in Florida in 2017, according to the attorney, Joel Leppard. Leppard has said that his client testified she didn’t think Gaetz knew the girl was underage, stopped their relationship when he found out and did not resume it until after she turned 18. The age of consent in Florida is 18.

“They’re grateful for the opportunity to move forward with their lives,” Leppard said Thursday. “They’re hoping that this brings final closure for all the parties involved.”

Gaetz has vehemently denied any wrongdoing and said last year that the Justice Department’s investigation into sex trafficking allegations involving underage girls had ended with no federal charges against him.

Gaetz’s political future is uncertain, at the moment.

He abruptly resigned his congressional seat upon being nominated to be attorney general. That move was seen as a way to shut down the ethics inquiry of allegations of sexual misconduct.

Republicans on the committee declined this week to release its findings, over objections from Democrats in a split vote. But the committee did agree to finish its work and is scheduled to meet again Dec. 5 to discuss the matter.

As word of Gaetz’s decision spread across the Capitol, Republican senators seemed divided.

Oklahoma Sen. Markwayne Mullin, who served with Gaetz in the House, said it was a “positive move.” Mississippi Sen. Roger Wicker said it was a “positive development.” Maine Sen. Susan Collins said Gaetz “put country first and I am pleased with his decision.”

Others said they had hoped Gaetz could have overhauled the department.

Florida Sen. Rick Scott, a close ally of Trump, said he was “disappointed. I like Matt and I think he would have changed the way DOJ is run.”

Kentucky Sen. Rand Paul said he hopes Trump will pick someone “equally as tenacious and equally as committed to rooting out and eliminating bias and politicization at the DOJ.”

Sen. Mike Rounds, R-S.D., suggested that Trump name Utah Sen. Mike Lee, a former prosecutor and member of the Senate Judiciary Committee. Trump needs someone he has confidence in, Rounds said, but also someone whom the Senate “recognizes, knows and also has confidence in.”

Rounds added that “the president has the right to make the nominations that he sees fit. But the Senate also has a responsibility for advice and consent. And in this particular case, I think there was advice offered rather than consent.”

Gaetz won reelection in November to the new Congress, which convenes Jan. 3. But it’s unclear whether he would take office.

In his Nov. 13 resignation letter to House Speaker Mike Johnson, R-La., Gaetz said, “I do not intend to take the oath of office for the same office in the 119th Congress, to pursue the position of Attorney General.”

Meanwhile, Florida has launched a special election process to fill the vacancy.