BAGHDAD — When Islamic State militants retreated from the embattled town of Jurf al-Sakher last week, the Iraqi military was quick to flaunt a rare victory against the extremist group, with state television showing tanks and Humvees parading through the town and soldiers touring government buildings that had been occupied by the militants since August.

However, photos soon emerged on independent Iraqi news websites revealing a more discreet presence — the powerful Iranian general Qassem Suleymani, whose name has become synonymous with the handful of victories attributed to Iraqi ground forces. Local commanders said Lebanon’s powerful Shiite Hezbollah group was also on the front lines.

Shiite militias have played a key role in driving the Islamic State out of the so-called Baghdad Belt of Sunni villages ringing the capital. But the sectarian militias have long been implicated in brutality against the country’s Sunnis, and while they have benefited from US-led airstrikes, their advance could undermine efforts to knit the troubled country together.

Militia commanders told the Associated Press that dozens of advisers from the Iranian Revolutionary Guard and the Lebanese Hezbollah were on the front lines in Jurf al-Sakher, providing weapons training to some 7,000 troops and militia fighters, and coordinating with military commanders ahead of the operation.

One commander, who agreed to be identified only by his nickname, Abu Zeinab, said Suleymani began planning the Jurf al-Sakher operation three months ago. The cleared town, 30 miles south of the capital, lies on a road often used by Shiite pilgrims, who will be heading in droves to the holy city of Karbala this week to commemorate the death of the Prophet Muhammad’s grandson, Imam Hussein, in a 7th-century battle that marked the beginning of the Sunni-Shiite divide.

Iraqi military officials declined to discuss Suleymani’s presence in Jurf al-Sakher, or in previous victories where he is known to have played a commanding role, including in the besieged town of Amirli in August and in the Shiite holy city of Samarra in June.

Hezbollah has openly joined Syrian President Bashar al-Assad’s forces against the mainly Sunni militants fighting to topple him — a decision that has fueled sectarian tensions in Lebanon. The Iran-backed group, however, has not commented on its involvement or lack thereof in Iraq. In Beirut, a Hezbollah spokesman declined to comment Wednesday, saying he was not authorized to discuss the subject.

In July, officials in Lebanon said a Hezbollah commander was killed while on a “jihadi mission” in Iraq. Ibrahim Mohammed al-Haj was buried in Lebanon and his funeral attended by top Hezbollah officials. It was the first known Hezbollah death in Iraq since the Islamic State’s lightning advance in June.

A Lebanese official close to the group said Hezbollah is known to have “a limited number of advisers” in Iraq who are not directly involved in fighting on the front lines, and that al-Haj was one of them. The official spoke on condition of anonymity because he was not authorized to talk to the media.

Iraqi officials have also said a handful of advisers from Hezbollah are offering front-line guidance to Iraqi Shiite militias fighting the Sunni extremists north of Baghdad. But it is not known if any Hezbollah men are actually fighting.

The US and Iran have found themselves on the same side in the war against the Islamic State, which rampaged across much of northern and western Iraq in June, seizing the country’s second-largest city, Mosul. But while US military advisers have been coordinating coalition airstrikes from within heavily fortified bases, Suleymani and his commanders are on the front lines and would assume a key role in the retaking of major cities.

That could prove a major impediment to addressing the grievances of Iraq’s Sunni minority. The militias were implicated in the mass killing of Sunnis at the height of the country’s sectarian carnage in 2006 and 2007 and have more recently been accused of brutalizing Sunni captives.

Sunnis are also deeply suspicious of Shiite powerhouse Iran, which has played an outsized role in Iraqi affairs since the 2003 US-led invasion that toppled Saddam Hussein’s Sunni-dominated government.

“It is true that Iraq needs any kind of help in the current situation, but this help should be public and part of the international efforts,” Sunni lawmaker Hamid al-Mutlaq told the AP. “This undeclared Iranian help harms national reconciliation and the sovereignty of Iraq.”

Amnesty International said last month that Shiite militias have abducted and killed scores of Sunni civilians with the tacit support of the government in retaliation for Islamic State attacks.

Iraq’s Prime Minister Haider al-Abadi has pledged to rein in the Shiite militias and establish a national guard to mobilize Sunnis against the extremists. But it could take months to assemble such a force, and in the meantime, Suleymani’s militias are in the best position to aid Iraq’s beleaguered military in regaining the initiative against the Islamic State.

Suleymani’s Quds Force, the special operations arm of Iran’s Revolutionary Guard, has been involved for years in training and financing Iraq’s Shiite militias. It has also long worked with Hezbollah in Lebanon and has been aiding Assad’s forces.

In June, Revolutionary Guard advisers under Suleymani provided guidance for Shiite militiamen in shelling Sunni insurgent positions around Samarra, a Sunni-majority city north of Baghdad that is home to a revered Shiite shrine, local commanders said. Suleymani was also seen as playing a key role in relieving the Islamic State siege of the Shiite Turkmen town of Amirli. And a top Revolutionary Guard general said in September that Suleymani had even helped Kurdish fighters defend their regional capital, Irbil.

Militia commanders, who spoke on condition of anonymity because they are not authorized to talk to the media, describe Suleymani as “fearless” — one pointing out that the Iranian general never wears a flak jacket, even on the front lines.

“Suleymani has taught us that death is the beginning of life, not the end of life,” one militia commander said.