Iraq’s new leader has taken significant steps to confront Iranian-linked militias that have targeted American troops, a top U.S. military official said Tuesday, adding that the United States must remain patient as Prime Minister Mustafa al-Kadhimi challenges groups with formidable military and political clout.

Marine Gen. Kenneth F. McKenzie Jr., who heads U.S. Central Command, commended Kadhimi for ordering a late June raid on a militia group the Pentagon has accused of launching repeated rocket attacks on American personnel in Iraq.

The unusual move against Kataib Hezbollah — which prompted an outcry from its leaders and the release of detained militiamen — illustrated the challenges that Kadhimi faces as he seeks to rein in militias without upsetting the fragile balance between Iraq’s two chief foreign backers, Washington and Tehran.

“He’s negotiating a land mine now. I think we need to help him,” McKenzie said after meeting with Kadhimi during a visit to Baghdad. “And he’s just got to kind of find his way, which means we’re going to have less-than-perfect solutions, which is nothing new in Iraq. But. . . I’m a glass-half-full guy when I look at the prime minister and what he’s doing.”

McKenzie’s visit with Kadhimi, a former intelligence chief who became premier in May, comes as the Trump administration conducts talks with Iraqi leaders aimed in part at defining the future of U.S. troops in Iraq.

Speaking to reporters by phone after leaving Iraq, McKenzie voiced confidence the Iraqi government would ask U.S. forces to stay in the country despite calls for a withdrawal earlier this year from Iraqi lawmakers angered by Washington’s decision to launch an airstrike in Baghdad that killed Qasem Soleimani, a top Iranian military commander, along with a senior Iraqi militia figure.

While both governments affirmed last month that American forces would not seek permanent bases in Iraq, U.S. military officials say some sort of continued presence is necessary given the ongoing threat from Islamic State militants. More than 5,000 U.S. troops are currently in Iraq.

The U.S. military presence acts as a deterrent to Iran’s influence there, the Trump administration says, but U.S. forces have been subject to repeated rocket and artillery attacks that officials attribute to Kataib Hezbollah and other militias.

McKenzie declined to say how many troops he believed would be needed, saying it would be up to civilian leaders. While President Trump has repeatedly stated his desire to remove troops from Syria and Afghanistan, he has spoken less frequently about Iraq.

Mick Mulroy, who served as a top Pentagon official for the Middle East earlier in the Trump administration, said a continued troop presence would also be beneficial “to the continuing development of the Iraqi military to defend itself against the malign activities of Iran.”

“Many of these militias look out for the interests of Iran over that of their own country,” said Mulroy, who now serves as a national security analyst for ABC News.

McKenzie also addressed, for the first time in public, intelligence reports about an alleged Russian program to pay Taliban-linked militants bounties to attack U.S. and NATO forces in Afghanistan.

While White House officials have downplayed the reports, saying they were not seen as conclusive enough to warrant taking action against Russia in response, other officials have said the intelligence was deemed credible and that the bounties may have resulted in American deaths. Lawmakers have been clamoring for more information.

McKenzie said he was very familiar with the intelligence but was “not convinced” that Russian payments to Taliban-linked figures resulted in American deaths.

“I found it very worrisome. I just didn’t find that there was a causative link there,” he said. It was proven enough to worry me. It wasn’t proved enough that I would take it to a court of law.

“That’s often true in battlefield intelligence. You see a lot of indicators. Many of them are troubling; many of them you act on. But in this case, there wasn’t enough there. . . . I just didn’t see enough there to tell me that the circuit was closed in that regard.”

The general said he had asked intelligence officials to continue to “dig on it,” which they are doing.

McKenzie said the reporting had not changed the military’s posture in Afghanistan.

“We take extreme force protection measures all the time in Afghanistan because, whether the Russians are paying the Taliban or not, over the past several years the Taliban have done their level best to carry out operations against us. So nothing has practically changed on the ground in terms of force protection,” he said.

Louisa Loveluck in London contributed to this report.