On Sunday, President Trump’s most senior national security advisers joined him at his Mar-a-Lago resort in Florida, where Trump was beginning the second week of his holiday vacation. The officials told reporters that U.S. F-15 Strike Eagles had just attacked Iranian-sponsored militia groups at their bases in Iraq and Syria, in response to a series of rocket attacks that had culminated in the death of an American contractor two days earlier.

But privately, a different topic had come up with an agitated president: whether to kill Iranian Maj. Gen. Qasem Soleimani, whom military leaders described as responsible for the attack on an American citizen and likely to kill more.

Why Trump chose this moment to explore an operation against the leader of Iran’s Quds Force, after tolerating Iranian aggression in the Persian Gulf for months, was a matter of debate within his own administration. Officials gave differing and incomplete accounts of the intelligence they said prompted Trump to act. Some said they were stunned by his decision, which could lead to war with one of America’s oldest adversaries in the Middle East.

“It was tremendously bold and even surprised many of us,” said a senior administration official with knowledge of high-level discussions among Trump and his advisers, who like others spoke on the condition of anonymity to discuss internal deliberations.

On Friday, hours after a U.S. drone killed Soleimani and an Iraqi militia leader at the Baghdad airport, senior State Department officials told reporters that Iran had been plotting “imminent attacks directed at killing hundreds of Americans” but declined to offer specifics. Secretary of State Mike Pompeo told CNN on Friday that Soleimani “was actively plotting in the region to take actions, the big action as he described it, that would have put dozens if not hundreds of American lives at risk. We know it was imminent.”

On Capitol Hill, officials briefed lawmakers and staff but did not provide any details about the alleged Iranian targets or what made them imminent, according to people who were present.

Some analysts were skeptical about the need to kill Soleimani.

“There may well have been an ongoing plot as Pompeo claims, but Soleimani was a decision-maker, not an operational asset himself,” said Jon Bateman, who served as a senior intelligence analyst on Iran at the Defense Intelligence Agency. “Killing him would be neither necessary nor sufficient to disrupt the operational progression of an imminent plot. What it might do instead is shock Iran’s decision calculus” and deter future attack plans, Bateman said.

In a conference call with reporters, national security adviser Robert C. O’Brien said Friday evening that the strike on Soleimani happened after he recently visited Damascus and was plotting to target U.S. military and diplomatic personnel.

“This strike was aimed at disrupting ongoing attacks that were being planned by Soleimani and deterring future Iranian attacks through their proxies or through the . . . Quds Force directly against Americans,” O’Brien said.

Defense officials described Soleimani’s planning as part of a continuation of earlier Iranian provocations, including the mining of ships in the Persian Gulf in May. A month later, Trump called off an airstrike at practically the last minute — an attack that had been intended to retaliate for Iran’s downing of a U.S. surveillance drone.

Army Gen. Mark A. Milley, chairman of the Joint Chiefs of Staff, said in a meeting with reporters Friday that Soleimani was killed after U.S. officials recently became aware of intelligence that showed the “size, scale, scope” of what he was planning, which led them to conclude that there was a greater risk in not taking action than in doing so.

“Is there risk? Damn right there’s risk,” Milley said of possible Iranian reactions to the killing one of the nation’s most prominent military leaders. “But we’re mitigating, and we think we’re taking appropriate mitigations.”

“The ball is in the Iranian court,” Milley said. “It is their choice what the next steps are.”

It may be days or weeks before U.S. officials know how Iran will respond. But the rapid sequence of events that led to Soleimani’s death made clear that a decades-old conflict has reached a fever pitch.

An American casualty

The immediate roots of the current crisis can be traced to the Friday after Christmas, when a barrage of missile fire exploded at K-1, a joint U.S.-Iraqi base on the southern edge of the northern Iraqi city of Kirkuk. Of about 30 rockets that American officials said were fired at the air base several hours after sundown, nine landed within the sprawling facility.

American officials quickly blamed Kataib Hezbollah, a powerful militia group they say receives funding and arms from Iran. In addition to wounding three U.S. soldiers and two Iraqi federal police, officials said the attack killed an American interpreter, whose identity has not been made public. That person had been working alongside a force of about 100 U.S. personnel on the base as part of a campaign against the Islamic State.

While the attack evoked the frequent rocket fire that rained down on U.S. troops in Baghdad and other locations in the years following the 2003 invasion, such incidents have been uncommon in recent years. The United States has found itself in the odd position of fighting on the same side as Iranian-backed militias against the Islamic State. But the rocket attacks resumed in recent months as the Trump administration continued its “maximum pressure” campaign of economic sanctions against Iran, growing in intensity until the Kirkuk attack.

“Thirty-one rockets aren’t designed as a warning shot. That’s designed to inflict damage and kill,” Milley told reporters before the Soleimani strike.

U.S. officials were disappointed that Iraq had not publicly condemned the Kirkuk attack and questioned the government’s willingness to check militias loyal to Iraq’s powerful neighbor.

Almost exactly 48 hours after the Kirkuk attack, American F-15 jets unleashed bombs on five militia sites. The targets included command nodes and weapons depots in Bu Kamal, Syria, and Qaim, Iraq, border outposts on either side of the Iraq-Syria border. Speaking later that day after meeting with Trump at Mar-a-Lago, Defense Secretary Mark T. Esper said the attacks were successful but also hinted at discussion of “other options” being considered.

“We will take additional actions as necessary to ensure that we act in our own self-defense and we deter further bad behavior,” he said.

The strikes created an immediate political crisis in Baghdad, where officials were given little notice of the plans by their chief Western ally to attack militias linked to their powerful neighbor.

The backlash was particularly fierce from militia leaders.

“The response will be harsh for the American forces in Iraq,” warned Jamal Jaafar Ibrahimi, deputy head of the Popular Mobilization Forces , better known as Abu Mahdi al-Muhandis. (Also the founder of the Kataib Hezbollah militia,Muhandis was killed in the U.S. strike on Soleimani.)

Two days later, on Tuesday, thousands of militia supporters converged on the U.S. Embassy in Baghdad, throwing molotov cocktails and breaching the secure compound’s reception areas before setting up a protest camp outside. As militiamen set fire to a reception area, smoke billowed out of the facility that had once symbolized U.S. influence and might in Iraq. Inside the compound, staff hunkered down in safe rooms. Military leaders immediately dispatched about 100 Marines to Baghdad, then sent another 750 troops to remain on standby in Kuwait.

Tensions appeared to subside the following day, when militia leaders issued instructions for the demonstrators to depart and the government appealed for calm. American officials, however, were exasperated that Iraqi leaders had responded slowly and that government security forces stood by while the militiamen besieged the embassy.

Trump decides to act

At his resort in Florida, the president was told that Soleimani was going to be coming to Baghdad; senior officials felt he was taunting the United States by showing up in the Iraqi capital, implying that he could move around with impunity.

Calls among the national security principals were convened by the vice president throughout the week after initial discussions on Sunday to kill Soleimani, a senior administration official said.

Officials reminded Trump that after the Iranians mined ships, downed the U.S. drone and allegedly attacked a Saudi oil facility, he had not responded. Acting now, they said, would send a message: “The argument is, if you don’t ever respond to them, they think they can get by with anything,” one White House official said.

Trump was also motivated to act by what he felt was negative coverage after his 2019 decision to call off the airstrike after Iran downed the U.S. surveillance drone, officials said. Trump was also frustrated that the details of his internal deliberations had leaked out and felt he looked weak, the officials said.

The United States tracked Soleimani’s movements for several days, keeping Trump apprised, and decided that their best opportunity to kill him would be near the Baghdad airport, the senior administration official said.

He ultimately gave final approval just before the strike, a senior administration official said, making the call from his golf resort.

Trump also had history on his mind. The president has long fixated on 2012 attacks on U.S. compounds in Benghazi, Libya, and the Obama administration’s response to them, said lawmakers and aides who have spoken to him, and he felt the response to this week’s attack on the embassy and the killing of an American contractor would make him look stronger compared with his predecessor.

“Benghazi has loomed large in his mind,” said Sen. Lindsey O. Graham (R-S.C.) in an interview, explaining the response this week.

Graham was at Mar-a-Lago on Monday and said the president told him he was concerned they “were going to hit us again” and that he was considering hitting the Iranians.

No specific plan was ready to kill Soleimani, but it was on Trump’s mind, Graham said.

“He was more thinking out loud, but he was determined to do something to protect Americans. Killing the contractor really changed the equation,” Graham said.

“He was saying, ‘This guy is a bad guy, he’s up to no good, we have to do something,’ ” Graham said.

After the attack, U.S. officials in Iraq braced themselves for a range of possible responses, from direct attacks by Iran to an Iraqi order that U.S. forces and personnel leave the country.

On Friday, Graham said the president described the job as “a tough business.”

“I said, ‘Yeah, it’s a tough business, Mr. President,’ ” Graham said.

Shane Harris and Karoun Demirjian contributed to this report.