BAGHDAD — An Iraqi militia commander whose arrest last month sparked a standoff between the government and paramilitary groups was freed Wednesday after a judge ordered his release.

The release of Qassim Mahmoud Musleh came as Iranian Gen. Esmail Ghaani, head of the expeditionary Quds Force, arrived in Baghdad to meet with militia and political leaders, two Shiite political officials said.

The officials said the meeting was to address ongoing tensions between the government and some militia groups linked to Iran following Musleh's arrest. The officials spoke on condition of anonymity because they were not authorized to speak to media.

Supporters of Musleh greeted him with hugs and kisses on Baghdad's central Jadriya Bridge after his release, taking photos and videos with him to celebrate. Two Iraqi officials said Musleh was released at 8 a.m. and he returned to the southern city of Karbala, his hometown, where supporters also greeted him.

Musleh is head of the Popular Mobilization Forces in Anbar province. He was arrested May 27 on terrorism charges following a judicial investigation. His release was ordered by an investigative judge within the PMF, to whom his case file had been sent, two Iraqi officials said.

Iraq's Supreme Judicial Council said Musleh was released because of insufficient evidence and that proper legal procedures had been followed — an apparent effort to dispel criticism over his release.

The PMF is a state-sanctioned group comprised of an array of militias formed to battle the Islamic State group in 2014. Among the most powerful members of the group are Iran-backed Shiite militia groups. Their growing clout within Iraq has troubled Western, especially U.S., officials and presented an ongoing challenge for Iraq's government.

Musleh's arrest sparked tensions and fears of violence when, shortly after, forces affiliated with the PMF surrounded Prime Minister Mustafa al-Kadhimi's headquarters inside the heavily fortified Green Zone, the seat of the Iraqi government.

Iraqi security forces and the elite Counter-Terrorism Service were deployed to protect the government and diplomatic missions. PMF factions had also gathered around the Green Zone's entrance gates.

It was the latest incident highlighting al-Kadhimi's ongoing challenge to impose the rule of law on militia groups. The groups are suspected of targeting anti-government protesters and outspoken activists as well as the American presence in Iraq.

Musleh's release was considered by many to be a win for the PMF in its standoff with the government.

In comments to local media in Karbala after his release, Musleh said: "The leadership of the PMF expect that they will be accused of terrorism. ... It has happened before and it is happening now. Enemies outside of Iraq are pointing fingers toward the leadership of the PMF ... the PMF is the one defending this country."

The charges had accused Musleh of corruption and complicity in the assassinations of Iraqi activists in Karbala, in particular the targeted killing of Ehab al-Wazni. Al-Wazni was an outspoken activist in Karbala whose death sparked outrage and protests across Iraq's south and Baghdad.

The Supreme Judicial Council said Wednesday investigative authorities were unable to produce evidence implicating Musleh in the death of al-Wazni, according to a statement.

"It was proven according to the passport information that (Musleh) was outside of Iraq when al-Wazni was assassinated and he denied committing or participating in this crime, and the investigative court did not find any evidence to prove his involvement in that crime, directly or indirectly," the statement said.

Following Musleh's detention, Al-Kadhimi held a meeting with key Shiite leaders to quell tensions. Based on the meeting's outcome, Musleh was taken into PMF custody.

Of particular concern during his detention was which Iraqi security body should have physical custody of Musleh. Al-Kadhimi's government was aware that a transfer to PMF security would be widely seen as a concession.

An investigative committee comprised of officials from the defense and interior ministries, National Security and the PMF was formed to look into his case. Musleh was in the custody of the Joint Operations Command during that time. The JOC oversees an array of Iraqi security forces.

On Monday, his file was sent to a PMF investigative judge, who ordered his release.

Ghaani's arrival in Baghdad coincided with Musleh's release. Officials said ongoing tensions were the subject of his meetings but did not elaborate further.

Attempts to arrest militia-affiliated individuals in the past have unfolded in a similar pattern, with pressure coming from militia groups and concessions on the part of the government.

A raid carried out by the Counter-Terrorism Service last summer against Iran-backed Kataib Hezbollah led to over a dozen arrests. All were eventually released after pressure and threats of violence against the government.