The American military appeared to inform Iraqi officials Monday that it was pulling out of the country with the leak of an unsigned letter drafted by the Marine general at the helm of the US-led coalition fighting ISIS in Iraq.

Defense Secretary Mark Esper later denied that the US had made a decision about a troop withdrawal, and the chairman of the Joint Chiefs of Staff, Gen. Mark Milley, called the letter “a draft’’ and “a mistake.’’

“There’s been no decision whatsoever to leave Iraq,” Esper insisted to reporters at the Pentagon.

The military chiefs’ comments came after the letter — unsigned but bearing the typed name of US Marine Corps Brig. Gen. William H. Seely III, the commanding general of Task Force Iraq — was leaked to media outlets.

“Sir, in deference to the sovereignty of the Republic of Iraq, and as requested by the Iraqi Parliament and the Prime Minister, CJTF-OIR will be repositioning forces over the course of the coming days and weeks to prepare for onward movement,” read the unsigned letter from Seely.

The letter said there would be an increase in helicopter travel around the Green Zone and said, “We respect your sovereign decision to order our departure,” adding that the operations would take place at night to avoid disrupting the Iraqi public and avoid the perception that troops were being added, not withdrawn.

Before Esper’s denials, the sudden announcement was an apparent about-face from the position taken by President Trump a day earlier, when he told reporters aboard Air Force One that he would slap tough sanctions on the country if its government followed through with a resolution from parliament to force US troops out.

The resolution passed Sunday was in retaliation for a US drone strike in Baghdad that killed a top Iranian military commander.

“If they do ask us to leave, if we don’t do it in a very friendly basis. We will charge them sanctions like they’ve never seen before ever. It’ll make Iranian sanctions look somewhat tame,” Trump said.

“If there’s any hostility, that they do anything we think is inappropriate, we are going to put sanctions on Iraq, very big sanctions on Iraq,” said Trump as he returned to Washington after spending the holidays at his Mar-a-Lago resort in Florida.

Iraq’s parliament earlier Sunday approved a non-binding resolution calling for all foreign troops to exit Iraq and urged Prime Minister Adel Abdul Mahdi to revoke the invitation to the US troops who have been helping Iraq defeat ISIS terrorists since 2014.

Trump said the US would need to be reimbursed for what it has spent so far. “We have a very extraordinarily expensive air base that’s there. It cost billions of dollars to build. Long before my time. We’re not leaving unless they pay us back for it,” the president said.

The Joint Chiefs chairman sought to address the confusion. “That letter is a draft. It was a mistake, it was unsigned, it should not have been released … (it was) poorly worded, implies withdrawal, that is not what’s happening,” Milley said later Monday.

“It’s an honest mistake … it should not have been sent,” he added.

Tensions escalated in Iraq last week after members of an Iranian-backed militia tried to storm the US Embassy in Baghdad, creating a two-day standoff with US security forces.

The assault on the diplomatic compound was in retaliation for US airstrikes on bases in Iraq and Syria belonging to Kataib Hezbollah that killed 25 fighters.

The US responded to a rocket attack by the group that killed an American contractor at an Iraqi base.

Then last Thursday, the US killed Qassem Soleimani, leader of the Quds Force and Iran’s top military leader, in a drone strike at Baghdad International Airport.

With Post wires