WEST PALM BEACH, Fla. — President Trump has quickly turned the U.S. drone killing of Iranian military commander Qasem Soleimani into a boast for the campaign trail, regaling supporters with tales of his role in the operation as he seeks to burnish his commander-in-chief credentials in an election year.

At a campaign rally in Milwaukee last week and in a private event with Republican donors at his Mar-a-Lago resort in Palm Beach, Fla., this weekend, Trump has cast Maj. Gen. Soleimani’s death this month as overdue justice for a man who denigrated the United States and used roadside explosives to kill and maim.

In doing so, Trump has not bothered to vigorously defend the legal justification for the drone strike he ordered. (The administration has said Soleimani was planning “imminent” attacks on U.S. assets but has not put forward detailed evidence.) Trump also seems to have abandoned his unfounded claim that up to four U.S. embassies were threatened after Defense Secretary Mark T. Esper and other top officials acknowledged they were not aware of such a threat.

Rather, Trump has focused on placing himself at the center of the action. In leaked audio from the GOP fundraiser, Trump described listening in the White House Situation Room to live updates from a U.S. official who counted down the seconds until the strike on Soleimani was carried out.

“Then, all of a sudden, boom,” the president said.

Other presidents have made the demise of high-profile national security threats a feature of their talking points for the campaign trail, including former president Barack Obama, who used the killing of al-Qaeda mastermind Osama bin Laden to push back against Republicans who had called him feckless during his run for reelection in 2012.

But Trump’s focus on Soleimani, as well as the killing of Islamic State leader Abu Bakr al-Baghdadi in a U.S. miliary raid in Syria this past fall, comes at a particularly fraught moment for a president who faces an impeachment trial in the Senate and has faced consistent criticism from Democrats, and some Republicans, for lacking the temperament to lead the country.

Last month, former vice president Joe Biden, a leading Democratic presidential candidate, unveiled a campaign ad featuring a viral video of foreign leaders laughing while privately talking about Trump at a NATO gathering. A group of prominent GOP political strategists launched a major fundraising effort to help defeat him in crucial swing states in 2020. And a new book — “A Very Stable Genius,” written by two Washington Post reporters — has offered alarming details of Trump dressing down U.S. military leaders and his own national security aides as “a bunch of dopes and babies” during a private briefing at the Pentagon in 2017.

By talking tough about the deaths of Soleimani and Baghdadi, Trump appeals “to an electorate who likes to hear those sorts of things,” said Bryan McGrath, a retired naval officer who helped organize one of two “Never Trump” letters signed by Republican national security experts in 2016. “Most importantly, he’s putting himself out there as a man of action, and I think that is appealing to his base.”

McGrath said he retains deep misgivings about Trump’s leadership, but, he added: “I like that Soleimani was taken out. I’m not exactly sure about all the planning that went into it. But I won’t hold that one against him.”

Since announcing Soleimani’s death, Trump has touted the operation as a measure of his resolve, criticizing Obama and former president George W. Bush for having passed up chances to kill the Iranian general. Both of them reportedly were concerned that such an act would lead to a war.

At his rally in Milwaukee on Tuesday, Trump spent much of the opening portion of his remarks boasting of his “bold and decisive action to defend American lives and deliver American justice” against “the world’s number one terrorist.”

Soleimani “was the king of the roadside bombs,” Trump said. “Great percentages of people don’t have legs right now and arms because of this son of a bitch, okay?” He hammered Democrats who questioned the rationale for the strike and his overall Iran strategy, saying his political rivals “should be outraged by Soleimani’s evil crimes, not the decision to end his wretched life.”

As he did in his remarks at the private GOP fundraiser, Trump at the rally re-created a purported conversation he had with another unnamed official — this one on the night that Iran responded to Soleimani’s killing by launching a dozen ballistic missiles at Iraqi military bases that house U.S. troops.

“I said, ‘How many killed?’ ‘Nobody, sir.’ I said, ‘How many hurt?’ They said, ‘Nobody, sir.’ And I said, ‘They just saved themselves $1 trillion and a lot of lives,’ ” Trump said, suggesting he would have escalated the conflict with additional sanctions and military strikes if U.S. personnel had been injured.

Despite Trump’s public statements that no Americans were wounded, at least eight U.S. troops suffered signs of concussions in the attack, officials said.

Robert Spalding, a retired Air Force general who served on Trump’s National Security Council, said the president’s use of Soleimani’s death as a political cudgel is “consistent with what’s been done in the past.”

“I don’t see it as something outside the realm of what other people have done,” he said. “Does talking about things like that burnish his credentials as a military leader? Well, I think that’s up to whoever is listening to it.”

Polls suggest Trump has not won over the public on his Iran strategy. According to an ABC News-Ipsos poll, 56 percent of the public disapprove of Trump’s approach on Iran, compared to 43 percent who approve. And 52 percent feel less safe after the strike on Soleimani vs. 25 percent who feel safer, the poll found. A Reuters poll taken before Iran’s missile attack found that 71 percent of the public believe war with Iran is very or somewhat likely over the next few years. Just 51 percent held that view in May.

Trump supporters have pointed to Iran’s public statements that it does not seek to further escalate the crisis as evidence that the president scored a tactical victory in taking out Tehran’s top military strategist with minimal costs to U.S. personnel.

But critics have noted that the confrontation led Iraq’s government to temporarily suspend counterterrorist operations against the Islamic State and vote to expel U.S. troops from the country, a demand Trump opposed this month.

Last week, Douglas London, a retired CIA officer, wrote in Just Security, a national security journal, that he feared Trump was focusing on big-name “celebrity” targets instead of more strategic operations. Along with Soleimani, London cited bin Laden’s son Hamza, who was killed this past summer in an operation in which the United States played a role.

“I am of the mind, knowing what a bad guy Soleimani was and the intelligence collection the U.S. is capable of, that it was quite probable that we had the intelligence case to justify this kind of operation” on Soleimani, said Ned Price, a former CIA officer who served as a spokesman for the National Security Council under Obama. “What worries me is the prospect that President Trump undertook an operation with an eye more to the politics than to the strategic context. This, to me, sounds like a president who wants to look and act tough as he enters the election cycle.”