WASHINGTON — President Donald Trump authorized the killing of Iranian Gen. Qassem Soleimani seven months ago if Iran's increased aggression resulted in the death of an American, according to five current and former senior administration officials.

The presidential directive in June came with the condition that Trump would have final signoff on any specific operation to kill Soleimani, officials said.

That decision explains why assassinating Soleimani was on the menu of options that the military presented to Trump two weeks ago for responding to an attack by Iranian proxies in Iraq, in which a U.S. contractor was killed and four U.S. service members were wounded, the officials said.

The timing, however, could undermine the Trump administration's stated justification for ordering the U.S. drone strike that killed Soleimani in Baghdad on Jan. 3. Officials have said Soleimani, the leader of the Islamic Revolutionary Guard Corps' elite Quds Force, was planning imminent attacks on Americans and had to be stopped.

"There have been a number of options presented to the president over the course of time," a senior administration official said, adding that it was "some time ago" that the president's aides put assassinating Soleimani on the list of potential responses to Iranian aggression.

After Iran shot down a U.S. drone in June, John Bolton, Trump's national security adviser at the time, urged Trump to retaliate by signing off on an operation to kill Soleimani, officials said. Secretary of State Mike Pompeo also wanted Trump to authorize the assassination, officials said.

But Trump rejected the idea, saying he'd take that step only if Iran crossed his red line: killing an American. The president's message was "that's only on the table if they hit Americans," according to a person briefed on the discussion.

Neither the White House nor the National Security Council responded to requests for comment. Bolton and the State Department also did not respond to requests for comment.

U.S. intelligence officials have closely tracked Soleimani's movements for years. When Trump came into office, Pompeo, who was Trump's first CIA director, urged the president to consider taking a more aggressive approach to Soleimani after showing him new intelligence on what a second senior administration official described as "very serious threats that didn't come to fruition."

Download the NBC News app for breaking news and politics

The idea of killing Soleimani came up in discussions in 2017 that Trump's national security adviser at the time, retired Army Lt. Gen. H.R. McMaster, was having with other administration officials about the president's broader national security strategy, officials said. But it was just one of a host of possible elements of Trump's "maximum pressure" campaign against Iran and "was not something that was thought of as a first move," said a former senior administration official involved in the discussions.

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

The idea did become more serious after McMaster was replaced in April 2018 by Bolton, a longtime Iran hawk and advocate for regime change in Tehran. Bolton left the White House in September — he said he resigned, while Trump said he fired him — following policy disagreements on Iran and other issues.

John Bolton, then the national security adviser, listens as President Donald Trump meets with Netherlands Prime Minister Mark Rutte at the White House on July 18, 2019. Jabin Botsford / The Washington Post/Getty Images file

The administration of President George W. Bush designated the Quds Force a foreign terrorist organization in 2007. Four years later, the Obama administration announced new sanctions on Soleimani and three other senior Quds Force officials in connection with an alleged plot to assassinate the Saudi ambassador to the United States.

But in April, Bolton helped prod Trump to designate the entire Islamic Revolutionary Guard Corps a foreign terrorist organization. White House officials at the time refused to say whether that meant the United States would target Revolutionary Guard leaders as it does the leadership of other terrorist groups, such as the Islamic State militant group and al Qaeda.

Iran retaliated by designating the U.S. military a terrorist organization.

The actions underscored the rising tension between the United States and Iran in the three years since Trump took office.

Get full coverage of the Iran crisis

Since Trump withdrew the United States from the Iran nuclear deal in 2018 — and his administration tightened its squeeze on Iran's economy with punishing economic sanctions — Iran has attacked U.S. military assets in Iraq with increasing aggressiveness and frequency.

Iran has launched more than a dozen separate rocket attacks on bases housing Americans since October. The U.S. military blamed Kataib Hezbollah, an Iraqi militia that is part of the Popular Mobilization Forces but is backed by Iran. U.S. military and intelligence officials say the group takes direction from Iran, specifically the Quds Force.

A U.S. military official in Iraq said the rockets Iran has launched at U.S. forces have become more sophisticated over time.

Most attacks in October and November used 107mm rockets, which have a shorter range and less explosive power. But an attack on Ain al Asad air base in Anbar Province on Dec. 3 included 122mm rockets, with more firepower and the ability to be fired from a greater distance. They are generally launched from more sophisticated improvised rail systems, leading the U.S. military to believe the attackers were receiving new equipment and training from Iran.

The largest attack was on Dec. 27, when Kataib Hezbollah launched more than 30 rockets at an Iraqi base in Kirkuk, killing a U.S. contractor and wounding four U.S. service members.

The base, known as K-1 Air Base, belongs to the Iraqi military but frequently hosts forces that are part of the U.S.-led coalition assigned to Operation Inherent Resolve, the fight against ISIS. On Dec. 27, the coalition was preparing for a counter-ISIS operation, so more Americans were on the base than usual.

After the attack, the United States launched airstrikes against five Kataib Hezbollah locations, three in Iraq and two in Syria, targeting ammunition and weapon supplies, as well as command and control sites.

Trump signed off on the operation to kill Soleimani after Iranian-backed militia members responded to the U.S. strikes by storming the U.S. Embassy compound in Baghdad.

Defense Secretary Mark Esper presented a series of response options to the president two weeks ago, including killing Soleimani. Esper presented the pros and cons of such an operation but made it clear that he was in favor of taking out Soleimani, officials said.

At a meeting later, military leaders laid out the estimated number of casualties associated with each option, showing the president that killing Soleimani at Imam Khomeini International Airport late at night would involve fewer possible casualties than the other options.

The strike marked a break from past administrations, which have never publicly claimed responsibility for killing senior figures from the Iranian regime or its proxies.

During the height of the U.S. war in Iraq in 2006, for example, when Iranian-armed and -trained militias were planting lethal roadside bombs targeting U.S. troops, Bush administration officials debated how to confront Soleimani and his operatives in Iraq, according to four former U.S. officials. U.S. troops captured Revolutionary Guard operatives but never tried to kill Soleimani or launch attacks inside Iranian territory, former officials said.

At one point, the U.S. commander in Iraq, Army Gen. George Casey, raised the possibility of designating Soleimani and his Quds Force officers as enemy combatants in Iraq, according to Eric Edelman, a former diplomat who held senior posts at the Defense Department and the White House. But in the end, the idea was ruled out as U.S. commanders and officials did not want to open up a new front in Iraq when U.S. forces were preoccupied with the fight against al Qaeda in Iraq, Edelman said.

"There were a lot of us who thought he should be taken out. But at the end of the day, they decided not to do that," Edelman said. There was concern about "the danger of escalation and the danger of having a conflict with Iran while we already had our hands full in Iraq," he said.

Iran responded to the assassination of Soleimani by striking bases housing U.S. forces in Iraq, and after no Americans were killed, Trump appeared to back off further military conflict. Instead, he announced new sanctions against Iran on Friday.