Members of the Iraqi Shiite Badr Army militia cheer on their way to take part in a military operation near the town of Tal Afar, west of Mosul, on Nov. 20. (Ahmed Jalil/European Pressphoto Agency)

The Iraqi parliament passed a law Saturday making militia units, including ­Iranian-backed groups accused of human rights abuses, an official part of the country’s security forces.

Lawmakers passed the measure 208 to 0 in a session that was boycotted by most Sunni politicians, who opposed an initiative that extends the influence of powerful Shiite groups that many Iraqi Sunnis view with suspicion.

Prime Minister Haider al-Abadi praised the law, saying that it gave due to fighters who had proved themselves a key part of Iraqi defenses since the onslaught by Islamic State militants in 2014.

“Those heroic fighters, young and old, need our loyalty for the sacrifices they have made,” a statement issued by Abadi’s office said. “This is the least we can do.”

But the measure, which also legitimizes smaller Sunni tribal groups that have fought alongside Iraqi forces since 2014, threatens to inflame sectarian tensions that could surge anew after the defeat of the Islamic State. It could also complicate Iraq’s military cooperation with the United States and other Western partners.

Some of the most powerful militias included in the “popular mobilization units” are closely aligned to Tehran, and the United States considers one of them a terrorist group. Some of the fighters have been accused of abuses and mistreatment of Sunnis in their response to the Islamic State.

The units, which have more than 110,000 members, were formed in the summer of 2014, partly in response to a call from Iraq’s most senior Shiite religious leader. They drew from existing militia groups and from volunteers who rushed to defend Iraq against its extremist adversary.

Since then, the units have played an important role in most of the major battles against the Islamic State. They are now conducting operations west of the city of Mosul, where a major government offensive is underway.

Militia groups were involved in attacks against the United States during the years after the 2003 invasion of Iraq. U.S. military leaders have said that groups such as Kitaeb Hezbollah, considered a terrorist organization by the U.S. government, and Asaib Ahl al-Haq were responsible for the deaths of at least 500 American military personnel.

Sunni politicians who opposed Saturday’s measure accused the parliament’s Shiite majority of ignoring their objections.

“What was passed today is a breach to the principle of the state and of balance in our security institutions,” Vice President Osama al-Nujaifi said in remarks released by the parliamentary media center. “It would weaken the Iraqi state and weaken hopes for building a stable Iraq.”

Raed al-Dahlaki, another Sunni politician, said the official status would give “legal cover to all these militias who committed and are still committing countless violations against the Iraqi people, like killing, kidnapping, looting and burning houses.”

While human rights groups have complained repeatedly about abuses by militia forces, the Abadi government has said it has identified only a few isolated actions. Last week, Abadi said the Mosul campaign has been conducted without such problems.

Salim al-Jubouri, a Sunni who is speaker of the Iraqi parliament, sought to reassure those worried by the measure, promising that the law would not grant immunity to those who had committed crimes or abuses in the past.

Jubouri said that once Iraq’s major cities have been cleared of the Islamic State, the popular mobilization units will be responsible for holding ground and maintaining security. But important details still must be worked out, such as who will command the troops on the ground and how they will be structured and funded.

Abadi’s office said the fighters will be under the prime minister’s direct control, as is Iraq’s elite counterterrorism force. ­Under former prime minister Nouri al-Maliki, that force was seen as having been used at times for the prime minister’s purposes.

“With a sensitive law like this one, the prime minister needs to be careful how he implements it,” said Ahmed al-Mayali, a political analyst.

The incorporation of groups such as Kitaeb Hezbollah into Iraqi security forces could require adjustments in the way security partners such as the United States assist Iraq with its security.

In addition to the approximately 6,000 U.S. troops on Iraqi soil, the United States sells weapons and aircraft to Iraq and provides training to its military. But U.S. law requires that military units receiving American assistance be vetted to ensure they are not guilty of abuses.

The U.S. Embassy in Baghdad declined to comment on the new law. The U.S. military has made a point of seeking to withhold air support to the militia units, although, at times, its firepower has helped those units indirectly.

Ahmed al-Asadi, a lawmaker who is also the spokesman for the government committee overseeing the mobilization units, said that once incorporated into the government, they will not retain their command structure.

“All the links they had previously to political parties will be severed, and it will be under the commander in chief,” he said.