When the military carried out President Donald Trump’s order to kill Iran’s top general, some hardened veterans of the decadeslong U.S.-Iran shadow war were troubled.

"Gobsmacked," was the single-word reaction of a former CIA officer who spent a career working against the targeted general, Qassem Soleimani, an Iranian spy master who helped kill hundreds of Americans.

The immediate concern was that Trump's move — the first known targeted killing of a foreign government official in recent decades — could set in motion a full-scale war, one that could crater the global economy, kill untold numbers of people and leave the United States stuck in yet another Middle East quagmire.

That hasn't happened — at least not yet.

An NBC News review of the events surrounding the Soleimani strike and the Iranian response, based on interviews with more than a dozen participants, shows that Washington and Tehran were closer to war than was generally understood. The officials provided new details, including that U.S. intelligence platforms observed the Iranians moving ballistic missiles and scattering their naval forces after Soleimani was killed, potential signs of an impending attack. Officials said the Americans were bracing for strikes on U.S. troops in Iraq by bomb-laden drones.

A burning vehicle at the Baghdad International Airport following an airstrike in Baghdad, early on Jan. 3, 2020. Iraqi Prime Minister Press Office / via AP file

The U.S. opted not to thwart the Iranian attack officials saw coming, and in the end, no Americans were killed when Iranian missiles struck U.S. positions, defusing the situation temporarily. But the two sides remain in a dangerous boxer’s clench, in which the smallest miscalculation, some officials believe, could lead to disaster. And American intelligence officials fully expect that Iran will pursue a further response, likely some sort of terrorist attack or assassination that doesn’t have obvious fingerprints.

This week, Brian Hook, the U.S. special representative for Iran, warned Soleimani’s replacement that he "will meet the same fate" if he kills Americans, and a top Iranian general responded that the U.S. will "definitely regret it" if the threats don’t cease.

Multiple current and former U.S. military commanders expressed concerns to NBC News that Trump — who campaigned on bringing American soldiers home from Middle East wars — may have become emboldened by the successes of the limited strikes he has ordered. Two former military officials said they worried that Trump — after the commando raid that killed the Islamic State militant group's leader, Abu Bakr al-Baghdadi, in Syria and the drone attack on Soleimani — may now become increasingly willing to pull the trigger, believing that military force can always be swift, decisive and relatively cost-free for the U.S. White House officials say Trump remains averse to commitments of ground troops, plans to bring many of them home and is determined to avoid a wider war.

A very small group of the most senior leaders had been looped into the plan to kill Soleimani, according to officials directly familiar with the matter. The consensus was that he presented the perfect target of opportunity — a middle-of-the-night missile strike in Iraq, not Iran, with a very low chance of civilian casualties. Military leaders knew the move would inflame tensions, but they believed Iran did not want a war. They saw this as a punch in the mouth that might just stun Iran into standing down, the officials said.

Trump agreed, a White House official said. In the president's mind, he was doing everything he could to avoid war.

"Believe it or not, we viewed the Soleimani strike as de-escalatory," the official said. "He was one guy, and the Iranian leaders knew what he was doing. They knew he was planning attacks on Americans."

A senior European intelligence official concurred, telling NBC News the strike "reset the calibration for the Iranians about the cost of doing business," and therefore may have reduced the risk of war, at least in the short term.

Following Soleimani's killing, Joint Chiefs Chairman Mark Milley said, "We would have been culpably negligent to the American people had we not made the decision we made."

Iranian Quds Force commander Qassem Soleimani, center, attends Iranian Supreme Leader Ayatollah Ali Khamenei's (not seen) meeting with the Islamic Revolutionary Guard Corps in Tehran, on Sept. 18, 2016. Press Office of Iranian Supreme Leader / via Getty Images file

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Trump believed he had to act to reestablish deterrence, the White House official said, because the Iranians had come to believe he would not use force. In December, rockets fired by an Iranian-backed militia killed an American contractor in northern Iraq. When the U.S. responded with airstrikes, Iranian-backed protesters swarmed the U.S. Embassy in Baghdad, forcing diplomats into panic rooms.

On Dec. 29, Secretary of State Mike Pompeo, Secretary of Defense Mark Esper and Milley flew to Trump's Mar-a-Lago club for a meeting, at which the president authorized the U.S. response, officials said.

The president signed off on a number of targets. Soleimani was the most significant, but Trump also authorized a strike against Abdul Reza Shahlai, an Iranian operative in Yemen. That strike was not successful.

Trump also authorized the bombing of Iranian ships, missile launchers and air defense systems, officials said. Technically, the military can now hit those targets without further presidential authorization, though in practice, it would consult with the White House before any such action.

Military officials say they knew the Soleimani strike was a gamble that could lead to war, and so the Pentagon made preparations.

For the first time since the 1980s, a special rapid reaction force (now called the Immediate Response Force) of the fabled 82nd Airborne Division was deployed. Another group of paratroopers from the 173rd Airborne Brigade was activated and prepared to deploy to Lebanon. The USS Bataan was on hand in the Mediterranean Sea to be ready in case American civilians had to be evacuated from Lebanon.

Perhaps the most dangerous moments came three days after Soleimani was killed, when U.S. intelligence detected signs that Iran was preparing to launch ballistic missiles, multiple U.S officials said. Trump had already been given an intelligence assessment that one of Iran’s likely responses to the Soleimani killing would be to launch missiles at Iraqi bases hosting American troops, bases that were unprotected by any missile defense systems, current and former officials said.

"There was no means to intercept those ballistic missiles," said Bradley Bowman, of the Foundation for Defense of Democracies, a Washington think tank that takes a hard line on Iran.

As a result, Bowman said, the U.S. was forced to send the troops to bunkers. “The Department of Defense made the decision that these Patriots were better utilized elsewhere," Bowman said, referring to the air defense missiles. He added that wasn’t necessarily a bad idea because the U.S. military was conducting a counter-ISIS mission and the threat from ISIS was not missiles.

Three current and one former American officials said the U.S. has requested sending Patriot missiles back to the bases in Ain al-Asad and Irbil.

With no option to intercept the Iranian missiles, the other possibility would have been to preemptively attack the missile launchers inside Iran. Yet, the Pentagon never presented Trump with an option to bomb the launchers, an official directly familiar with the matter said — a move that would have ensured the weapons could not be used to kill Americans but might have prompted a wider conflict.

Another concern, officials said, was that Iran would send bomb-laden drones against U.S. forces in Iraq.

The U.S. also observed that Iran was scattering its navy ships, a move designed to make them harder to hit, several officials said. Iran frequently disperses its ships when it is preparing to attack or to defend against an attack. The U.S. military assesses it could cripple the Iranian navy in minutes and take it out completely in less than two days, according to three current and former military officials.

Killing Soleimani may have brought the U.S. closer to conflict with Iran than it has been in years. But tensions were very high between the two nations last summer, too, after Iran shot down a U.S. drone in June.

Hours after that shootdown, Trump decided to retaliate by striking military targets inside Iran. After a White House meeting in which Trump was briefed on retaliatory strikes, the president called Gen. Joseph Dunford, then-chairman of the Joint Chiefs of Staff, according to multiple officials briefed on the meeting. Trump asked Dunford how many people could die if the U.S. struck inside Iran. Dunford said the estimates ran as high as 150. Trump said he believed that was too high a death toll in response to the destruction of an unmanned drone, the officials said.

Minutes before the attack was to proceed last summer, Trump called it off, to the relief of some U.S. military officials who worried a strike inside Iran could escalate quickly into a wider conflict, according to the officials.

After the Soleimani strike, which also killed other members of his convoy including the deputy head of an Iraqi anti-American militia, the U.S. sent a message to Iran through Swiss diplomats, threatening an overwhelming response if Iran went through with the retaliatory missile attacks, two U.S. officials said.

As they braced for possible missile or drone attacks by Iran, Americans took cover in bunkers at bases throughout Iraq, officials said. For several hours, military officials believed Iran would send drones to crash into bases, so they kept troops and civilians under cover and in body armor.

U.S. commanders in Iraq also were prepared for the possibility that bases could come under ground attack by pro-Iranian militias. To guard against that possibility, soldiers at the base said, some troops at Ain al-Asad stayed out of bunkers and instead patrolled the base. They faced significantly greater risks than those hunkered down in the concrete bunkers, which included heavily fortified shelters built during the era of the Iraqi dictator Saddam Hussein.

American early warning systems, including a special National Security Agency monitoring center, detected the Iranian missiles as they launched, so when the missiles hit, most troops had taken cover and there were few casualties. Some of the missiles landed in open fields. And while 64 service members suffered brain injuries, no American was killed, and Trump declared that "all is well."

The damage at Ain al-Asad military air base housing U.S. and other foreign troops in the western Iraqi province of Anbar on Jan. 13, 2020. Ayman Henna / AFP - Getty Images file

Whether the Iranians intended to kill Americans is a matter of debate within the government. The CIA assesses that the missile strike was designed to minimize casualties, U.S. intelligence officials said. Analysts believe Iran knew the U.S. would see the preparations and detect the launch, and for good measure, Iran warned Iraq that the missiles were coming. CIA analysts believe the strike was a move by Iran’s rulers to show their people they had hit back, without further escalating the situation.

Military officials are less sure. They believe Iran did hope to kill some Americans, and that it was only because the early warning systems worked that nobody died, Milley has said.

But on this, nearly every U.S. official agrees: It was mostly luck that not a single American died, and the missile attack represented a huge gamble by Iran. Had they killed even a single U.S. soldier, Trump might have felt compelled to respond with a counterstrike.

In a statement, an Iranian government spokesman said its response was proportionate and no further escalation of hostilities is expected.

"Iran's response to the unlawful, brutal, and extrajudicial assassination of General Soleimani, a high ranking member of the official military apparatus of the Islamic Republic of Iran (that is not at war with any other nation), and a well-known anti-ISIS hero in the region, was proportionate and in accordance with international law in particular our inherent right to self-defense as enshrined in the U.N. Charter," the spokesman, Alireza Miryousefi, said.

"Iran, as a sovereign member nation of the U.N., does not anticipate any further escalation of hostilities, but is fully committed in defending its sovereignty, citizens and interests against any possible aggression.”