By Phil Stewart

BAGHDAD (Reuters) - The U.S. military is "not in Iraq to seize anybody's oil", Defense Secretary Jim Mattis said, distancing himself from remarks by President Donald Trump, as he held talks with Iraqi leaders on Monday.

Mattis was the highest-ranking Trump administration official to visit Iraq since Trump irked Iraqis with a temporary ban on travel to the United States and for saying America should have seized Iraq's oil after toppling Saddam Hussein in 2003.

Trump told CIA staff in January: "We should have kept the oil. But okay. Maybe you'll have another chance."

Mattis, however, flatly ruled out any such intent. "We're not in Iraq to seize anybody's oil," he told reporters traveling with him late on Sunday, ahead of his arrival.

"All of us in America have generally paid for our gas and oil all along and I'm sure that we will continue to do so in the future," said Mattis, a retired Marine general who once led forces in Iraq.

His remarks are the latest sign of differences with Trump. Trump has acknowledged that Mattis disagrees with him about the usefulness of torture in interrogation and said he would defer to his defense secretary on the issue.

Mattis has been more critical than Trump of RussianPresident Vladimir Putin, and distanced himself from Trump's labeling of the media as "the enemy of the American people", saying he had no problems with the press.

A retired Marine general who led American troops in Iraq, Mattis has sought an exemption from Trump's travel ban for Iraqis who have served with U.S. troops, including translators.

He said he had not seen a new executive order which the administration is considering. "But I right now am assured that we will take steps to allow those who have fought alongside us, for example, to be allowed into the United States," Mattis said.

Mattis' visit came a day after Iraqi Prime Minister Haideral-Abadi announced the start of a ground offensive on westernMosul, where Islamic State militants are under siege along with an estimated 650,000 civilians.

It was unclear whether Trump's remarks on oil had come up during Mattis' with Abadi, who has told Washington that Iraq's oil is the property of Iraqis.

Mattis also met Iraq's defense minister and top U.S. officials in Iraq.

WILL US FORCES STAY AFTER MOSUL?

Influential Shi'ite cleric Moqtada al-Sadr on Monday called on Iraq's government to order the withdrawal of U.S. and allied forces after the battle of Mosul is over.

"The Iraqi government has to demand that all occupying and so-called friendly forces leave Iraq in order to preserve the prestige and the sovereignty of the state," Sadr said.

Mattis declined to address Sadr's remarks directly, describing them as an internal political matter.

But he said he was reassured after his talks in Baghdad that Iraq's leaders recognized the value of its relationship with the United States.

"I imagine we’ll be in this fight for a while and we’ll stand by each other," he said, repeatedly praising the resilience of Iraqi forces.

The U.S. commander in Iraq, Army Lieutenant General StephenTownsend, has said he believes U.S.-backed forces will recapture both of Islamic State's major strongholds - Mosul and the city of Raqqa in Syria - within the next six months.

Trump is looking for a plan to accelerate the campaign against Islamic State, which could lead to an additional deployment of U.S. forces, who currently number less than 6,000 in Iraq and Syria.

The Pentagon may also look at increasing the number of attack helicopters and air strikes and bringing in more artillery, as well as granting greater authority to battlefield commanders fighting Islamic State.

Townsend told a news conference in Baghdad he had been putting U.S. military advisers closer to front lines in Mosul than before, a move that would increase risk but bolster their ability to aid Iraqis, including by directing air strikes.    

"We adjusted our posture during the east Mosul fight and we embedded advisers a bit further down into the formation," he said.

Townsend added he was certain victory in Mosul was within sight. "The Iraqi security forces are going to take that city back. No doubt about it," he said.

(With reporting by Maher Chmaytelli in Baghdad; Editing by Alison Williams and Andrew Roche)