WASHINGTON— Donald Trump has chosen former Florida Attorney General Pam Bondi to run the Justice Department, announcing his pick hours after Matt Gaetz withdrew from consideration under a cloud of sexual-misconduct allegations.

“Pam will refocus the DOJ to its intended purpose of fighting Crime, and Making America Safe Again,” Trump said on Truth Social. “I have known Pam for many years — She is smart and tough, and is an AMERICA FIRST Fighter, who will do a terrific job as Attorney General!”

Gaetz stepped aside a week after Trump said he was the best person to remake the Justice Department, amid indications that Republican lawmakers were prepared to reject his nomination. His selection for attorney general had briefly positioned him to lead the very agency that once investigated whether he had a sexual relationship with an underage girl and violated sex trafficking laws, but the Justice Department ultimately didn’t bring charges.

Gaetz’s withdrawal marks the biggest political blow for Trump since his election to a second presidential term and comes as he continues to roll out contentious and unconventional selections for top government posts. Several other of his choices are under fire or face uncertain paths to confirmation, including ​​Pete Hegseth as secretary of defense, Robert F. Kennedy Jr. as Health and Human Services secretary, and former Rep. Tulsi Gabbard as director of national intelligence.

Bondi, a 59-year-old Republican who worked for years as a prosecutor, is a more conventional pick than Gaetz. She has had a close relationship with Trump for years and served on his legal team during his first impeachment. She has led the legal arm of the Trump-tied America First Policy Institute and worked as a partner at Ballard Partners, the lobbying firm that once employed Trump’s incoming chief of staff, Susie Wiles. Bondi frequently appears on Fox News, including as a guest host for “The Five.”

Trump told Bondi she was his choice for attorney general on Thursday evening at his Mar-a-Lago home. If confirmed, Bondi would become the third woman in the role.

In contrast with Gaetz, Bondi immediately drew praise from Senate Republicans after being named as Trump’s attorney general pick. Sen. Mike Lee (R., Utah) referred to her on social media as the “next attorney general” and said he looked forward to supporting her confirmation. In another social-media post, Sen. Lindsey Graham (R., S.C.) called Bondi a “grand slam, touchdown, hole in one, ace, hat trick, slam dunk, Olympic gold medal pick” who should be confirmed quickly.

Selecting an attorney general has been Trump’s top personal priority as he looks to bring the Justice Department he has railed against under closer presidential control. Gaetz had been seen as willing to help bend the institution to Trump’s will, echoing the president-elect’s criticism that the department under the Biden administration targeted Trump for political reasons.

For years Trump clashed with the department as it investigated him and his allies, and he expressed regret over his attorney general choices in his first term, Jeff Sessions and William Barr, who resisted some of his most extreme demands. He had been searching for an attorney general who would be more willing to do his bidding as he has threatened to seek retribution against his political rivals.

With the selection of Bondi, Trump puts a less divisive loyalist in position to lead the agency. Bondi appeared frequently as a surrogate during Trump’s latest campaign, and spoke at one of his final rallies earlier this month. She emerged as a critic of the criminal cases against Trump and the prosecutors behind them, accusing them of weaponizing the legal system.

As Florida’s attorney general, Bondi endorsed Trump a day before the state’s presidential primary in 2016, favoring him over Sen. Marco Rubio, a fellow Floridian whom Trump has now chosen to be secretary of state. The backing attracted scrutiny to a $25,000 donation Trump gave in 2013 to a political committee supporting Bondi’s re-election to attorney general.

The contribution came just days after news reports that she was reviewing allegations in a New York-based lawsuit that alleged the now-defunct Trump University was a sham. Bondi ultimately declined to join the lawsuit against the school, and has denied any connection between the donation and the decision.

Trump has turned to the ranks of his criminal defense team for other top Justice Department roles. Last week, he named his lawyer Todd Blanche, a former federal prosecutor in Manhattan, as his pick for deputy attorney general —the second-ranking Justice Department position—and selected Emil Bove and D. John Sauer for other leadership posts.

Corrections & Amplifications undefined If confirmed as attorney general, Pam Bondi would become the third woman in the role. An earlier version of this article incorrectly said she would be the second woman in the role. (Corrected on Nov. 21)

Write to Sadie Gurman at sadie.gurman@wsj.com and C. Ryan Barber at ryan.barber@wsj.com