The US has killed Iranian Major-General Qasem Soleimani, head of the elite Quds Force and architect of Iran's spreading military influence in the Middle East, in an air strike at Baghdad airport, the Pentagon and Iran said.
Top Iraqi militia commander Abu Mahdi al-Muhandis, an adviser to General Soleimani, was also killed in the attack, a militia spokesman said.
General Soleimani's killing marks a dramatic escalation in the regional "shadow war" between Iran and the US and its allies, principally Israel and Saudi Arabia, which could quickly increase tit-for-tat attacks.
The US embassy in Baghdad has urged its citizens to "depart Iraq immediately" after the air strike.
Iran has been locked in a long conflict with the US that escalated sharply last week with an attack on the US embassy in Iraq by pro-Iranian militiamen following a US air raid on the Kataib Hezbollah militia, founded by Muhandis.
"At the direction of the President, the US military has taken decisive defensive action to protect US personnel abroad by killing Qassem Soleimani," the Pentagon said in a statement.
"This strike was aimed at deterring future Iranian attack plans," it added.
US officials, speaking on the condition of anonymity, said that General Soleimani had been killed in a drone strike.
Iran's Revolutionary Guards said he was killed in an attack by American helicopters.
Pictures showed burning debris on a road near the airport.
Ayatollah Khamenei said harsh revenge awaited the "criminals" who killed General Soleimani and his death, though bitter, would double the motivation of the resistance against the US and Israel.
"All enemies should know that the jihad of resistance will continue with a doubled motivation, and a definite victory awaits the fighters in the holy war," he said in a statement carried by state television, in which he called for three days of national mourning.
State television presenters wore black and broadcast footage of General Soleimani peering through binoculars across a desert and greeting a soldier.
Ahmed al-Assadi, a spokesman for Iraq's Popular Mobilisation Forces (PMF), the umbrella grouping of Iran-backed militias, blamed the US and Israel.
Iraqi paramilitary groups said three rockets hit Baghdad International Airport, killing five members of Iraqi paramilitary groups and two "guests".
The rockets landed near the air cargo terminal, burning two vehicles, killing and injuring several people.
Local militia commander Abu Muntathar al-Hussaini said: "Soleimani and Abu Mahdi al-Muhandis were riding in one vehicle when it was struck by two successive guided missiles launched from an American helicopter while they were on their way from the arrivals hall on the road that leads out of Baghdad Airport."
He said the second vehicle was carrying bodyguards from the PMF and was hit by one rocket.
"The American criminals had detailed information on the convoy's movements," Mr Hussaini said.
Oil prices were up $3 on the news.
The slain commander's Quds Force, along with its stable of paramilitary proxies from Lebanon's Hezbollah to the PMF in Iraq, has ample means to launch a multi-barrelled response against its enemies.
In September, US officials blamed Iran for devastating missile and drone attacks on oil installations of Saudi Aramco, the Saudi state energy giant and world's largest oil exporter. The Trump administration did not respond, beyond heated rhetoric and threats.
Iran, for its part, has absorbed scores of air strikes and missile attacks, mainly carried out by Israel against its fighters and proxies in Syria and Iraq.
But analysts say Iran is likely to respond forcefully to the targeting of General Soleimani, who it has built into a legend as its influence has spread across the region in the wake of the US-led invasion of Iraq in 2003 and subsequent occupation.
General Soleimani, who has led the foreign arm of the Revolutionary Guards and has had a key role in fighting in Syria and Iraq, acquired celebrity status at home and abroad.
The US and Iran's regional foes Saudi Arabia and Israel have struggled to keep Iran's influence in check.
General Soleimani survived several assassination attempts against him by western, Israeli and Arab agencies over the past two decades.
His Quds Force, tasked with carrying out operations beyond Iran's borders, shored up support for Syrian President Bashar al-Assad when he looked close to defeat in the civil war raging since 2011 and also helped militiamen defeat Islamic State in Iraq.
He became head of the Quds Force in 1998, a position in which he kept a low profile for years while he strengthened Iran's ties with Hezbollah in Lebanon, Syria's government and Shia militia groups in Iraq.
Mr Muhandis, who was killed with General Soleimani, oversaw Iraq's PMF, a grouping of paramilitary groups mostly consisting of Iran-backed Shia militias that was formally integrated into Iraqi armed forces.
His Kataib Hezbollah militia, which received battlefield training from Lebanon’s Hezbollah, has long targeted US forces and was one of the earliest groups to dispatch fighters to Syria to support Mr Assad.
In 2009, Washington declared Kataib Hezbollah a foreign terrorist organisation, saying it threatened stability in Iraq and declared Mr Muhandis a terrorist.
In 2007, a Kuwaiti court sentenced him to death in absentia for his involvement in the 1983 US and French embassy bombings in Kuwait.