Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A few days after the Trump administration announced a new, get-tough approach to Iran, one of that country's top military commanders and the armed Shiite militias he supports played a key role in the seizure of an important Iraqi city from the U.S.-backed Kurds, according to Iraqi, Kurdish and American officials.

Former U.S. national security officials told NBC News the Iranian-brokered seizure of oil-rich Kirkuk by the Iraqi government and its militia partners, which heightens the risk of civil war, amounts to an embarrassing strategic blow to the U.S. at the hands of Iran.

"It is a catastrophic defeat for the United States and a fantastic victory for Iran's Revolutionary Guard, proving that Qassem Soleimani gets his way once again," said Ali Khedery, a former senior adviser on Iraq policy in the Bush and Obama administrations.

Soleimani is head of the Iranian military's special forces and extraterritorial operations. The major general commands an elite unit known as the Quds Force and has been dubbed the most powerful intelligence operative in the Middle East. According to Kurdish and Iraqi officials, he traveled to Kirkuk last week to weigh in on the dispute between Baghdad and the Kurds over the strategically important city of Kirkuk.

Iranian Quds Force commander Qassem Soleimani (C) attends Iranian supreme leader Ayatollah Ali Khamenei's (not seen) meeting with the Islamic Revolution Guards Corps (IRGC) on September 18, 2016 in Tehran, Iran. Anadolu Agency / Getty Images file

Kurdish officials and former U.S. intelligence officials told NBC News Soleimani helped negotiate a deal under which one Kurdish faction would abandon its checkpoints and allow Iraqi government forces, backed by Iranian-supported Shiite militias, to take the city uncontested. That explains, they say, why there was so little fighting as Iraqi forces, armed with heavy weapons provided by the U.S., seized Kirkuk from the Kurds, who also carry American weapons and have been the most stalwart U.S. ally in the fight against ISIS.

"It is a catastrophic defeat for the United States."

"We're confident that Qassem Soleimani engineered, guided, directed, manipulated this deal," Bayan Sami Abdul Rahman, the Kurdish representative in Washington, told NBC News.

She said Soleimani used a carrot-and-stick approach, threatening force and offering financial inducements to certain elements of a Kurdish faction whose soldiers abandoned their positions.

A spokesman for Iraq's Shiite-dominated paramilitary forces, Mouin al-Khadhimy, acknowledged to NBC News that Soleimani was in Iraq in recent days — to ease tensions between Iraqi and Kurdish forces, al Khadhimy said.

Ali Akbar Velayati, a foreign policy adviser to Iran's Supreme Leader Ayatollah Ali Khamenei, said in an Oct. 17 statment reported by Al-Monitor that "Iran plays no role in the Kirkuk operation."

President Donald Trump said the U.S. wasn't taking sides, and his government neither condemned the move by Baghdad nor mentioned the Iranian component.

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

"We remain very concerned about the situation in northern Iraq," said Michael Anton, spokesman for the National Security Council. "We urge both parties to stand down and resolve any dispute peacefully and politically, remain united in the fight against ISIS and remain united against a common threat in Iran."

Kurdish gunmen take up position on a street in central Kirkuk city, northern Iraq, on Oct. 16, 2017. Afan Abdulkhaleq / EPA

Sen. John McCain (R-Ariz.) warned Monday there would be "severe consequences" if Baghdad used U.S. arms against the Kurds.

"The United States provided equipment and training to the government of Iraq to fight [the Islamic State in Iraq and Syria (ISIS)] and secure itself from external threats — not to attack elements of one of its own regional governments, which is a longstanding and valuable partner of the United States," McCain, the chairman of the Senate Armed Services Committee, said in a statement.

Critics accused Trump of wilting in the face of Iran's tough tactics.

"This is the first real tangible challenge to the Trump Iran doctrine, and we have our answer: it seems like there is nothing behind it," Michael Barbero, a retired U.S. Army lieutenant general who served in Iraq and has close ties to the Kurds, told NBC News.

By allowing Iran to facilitate an Iraqi takeover of Kirkuk, Khedery added, "We have undermined our secular moderate, Western-leaning Kurdish allies in the Middle East. Our foes will be emboldened, our allies shaken."

This is the first real tangible challenge to the Trump Iran doctrine."

U.S. officials, not authorized to be named speaking publicly, disputed the idea that Iran got the better of the Trump administration. They argue that Kirkuk was always going to be a flashpoint between Baghdad and the Kurds, whether or not Iran was involved. Iran's heavy involvement in Iraq has long been a fact of life, they say — something the U.S. has no choice but to live with.

U.S. officials have long sought to convince the Kurds to postpone a referendum declaring independence from Iraq. After U.S. forces left Iraq in 2011, Vice President Joseph Biden and other American officials conducted hours of diplomacy in an effort to mediate the situation.

Iraqi police monitor as people gather in the street in the city of Kirkuk to celebrate on Oct. 18, 2017, after Iraqi government forces retook almost all the territory disputed between Baghdad and the autonomous Kurdish region, crippling its hopes of independence after a controversial referendum. Ahmad Al-Rubaye / AFP - Getty Images

Brett McGurk, the U.S. diplomat most closely focused on Iraq and ISIS policy, was unable to convince the Kurds to continue postponing the vote, which finally occurred in September. Once the Kurds voted overwhelmingly in favor of separating, American officials declared the referendum illegitimate, in keeping with their policy of trying to maintain Iraq as a single country.

"We were never going to support the Kurds in a fight with the Iraqi government," one U.S. intelligence official told NBC News.

The referendum put the focus on Kirkuk, a multi-ethnic city rich with oil fields that historically has been part of the Kurdish region. Saddam Hussein orchestrated a mass movement of Arabs to the city, displacing Kurds from their homes. In the years after his fall, Kurds began returning, but the occupying American forces carefully mediated the status of the city between Baghdad and the Kurds.

In public, U.S. officials tried to downplay the role of Iranian-backed Shiite militias in seizing Kirkuk.

Asked about it Tuesday, a Pentagon spokesman, Army Col. Ryan Dillon, said, "We do not have reports of…the types of units that you had mentioned."

Iraqi people celebrate after Kirkuk was seized by Iraqi forces as they gather on the street of Baghdad, Iraq on Oct. 18, 2017. Khalid al-Mousily / Reuters

However, Kurdish officials point to a Facebook video of a ceremony in which the Iraqi flag was raised at a government building. It shows two controversial figures on hand: Hadi al-Amiri, the head of the Badr Organization, an Iranian-backed political party; and Abu Mahdi al-Muhandis, who has been sanctioned by the U.S. Treasury for acts of violence against Americans, and is considered a close adviser to Soleimani.

Three days before that flag raising, on Oct. 13, Trump announced his new Iran strategy.

"Our policy is based on a clear-eyed assessment of the Iranian dictatorship, its sponsorship of terrorism, and its continuing aggression in the Middle East and all around the world," Trump said.

Trump also announced new sanctions on Iran's Revolutionary Guards (IRGC).

The timing of the Kirkuk incursion was not a coincidence, Khedery said.

"Iran is intentionally seeking to challenge and humiliate President Trump only days after the U.S. designated the IRGC," he said. "Tehran is testing our resolve, and our allies and foes are all closely watching how this will unfold."