By Dion Nissenbaum, Isabel Coles, Wall Street Journal–

In the hours after President Trump declared that the U.S. and Iran were backing away from open conflict, militants in Baghdad fired two rockets that set off warning sirens at the U.S. Embassy.

The blasts late Wednesday caused little damage, but they appeared to be a sign that Iraqi militia groups aligned with Iran could still play spoilers in the volatile conflict between Washington and Tehran.

The groups have made clear they still want to exact revenge on America for last Friday’s drone strike in Baghdad.

That U.S. attack killed not only Iranian Maj. Gen. Qassem Soleimani, Tehran’s most important military leader, but also Iraq’s top paramilitary commander, Abu Mahdi al-Mohandes. As Iran’s point man in Iraq, Mr. Mohandes played an important role in exerting control over militias that are formally part of Iraq’s security forces, but often pursue their own agendas.

In the past, Iran has relied on those militias—along with similar allies in places such as Lebanon and Yemen—to act as proxies in the region, conducting attacks that couldn’t be linked directly back to Tehran.

Last month, one of those militias launched the rocket attack that killed an Iraqi-American contractor working on a base in northern Iraq, triggering the military escalation that led to the killing of Messrs. Mohandes and Soleimani.

Now it is less clear how the groups will proceed. Some could continue launching attacks to avenge Mr. Mohandes’s death, or they could act with the backing of hard-liners in Tehran who want to keep pressuring the U.S., potentially triggering new rounds of escalation.

“I would still expect a longer, less obvious form of Iranian response in the wider region,” said Henry Boyd, a research fellow for defense and military analysis at the International Institute for Strategic Studies in London. “The wider pressure on the Iranian regime to demonstrate its continued powers of resistance and action remains.”

Tehran has indicated its retaliatory strikes were finished after firing more than a dozen ballistic missiles at two Iraqi bases containing U.S. forces. They inflicted only modest damage and claimed no American or Iraqi lives. Mr. Trump said Iran was “standing down.”

But the longer-term goal of Iran and its allies in Iraq is to expel U.S. troops from the country.

One paramilitary commander, Qais al-Khazali, said the U.S.’s refusal to withdraw troops immediately after Iraq’s parliament voted in favor of their expulsion last Sunday compelled the “resistance groups” to act and form a unified front to end the American military presence.

“The initial Iranian response came to the assassination of the martyred commander Soleimani,” he said. “Now it is time for the initial Iraqi response to the assassination of the martyred commander Muhandis,” he added, referring to Mr. Mohandes. “Because Iraqis are brave and fervent, their response will not be less in magnitude than the Iranian response.”

That may be more of a boast. The Iraqi paramilitary forces don’t have the same kinds of ballistic missiles or advanced weapons to carry out the kind of strike Iran launched this week. But they do have the ability to kill Americans, as they did in last month’s attack at the base in northern Iraq.

Some analysts say Iran has provided some of its allies in Iraq with short-range ballistic missiles that are already a major concern for the U.S. and Israel, which has carried out airstrikes on some of their storehouses.

Iraqi paramilitary groups also led last month’s assault on the U.S. Embassy in Baghdad, which drove Mr. Trump to order the drone strike on the two military commanders.

U.S. officials said they were getting positive signs that Iran was advising the militias in Iraq to stand down.

“We’re receiving some encouraging intelligence that Iran is sending messages to those very same militias not to move against American targets or civilians,” Vice President Mike Pence said Wednesday night on CBS News. “And we hope that that message continues to echo.”

Iran may have an incentive to keep the groups in check. The Trump administration has repeatedly said it holds Iran directly responsible for the actions of its allies in Iraq.

Kataib Hezbollah, which the U.S. blames for many of the attacks targeting its troops in Iraq, advised against knee-jerk reactions “to achieve the best possible results, the first of which is the expulsion of the American enemy.”

Populist cleric Moqtada al-Sadr, who signaled the reactivation of his Mahdi Army militia in the wake of Mr. Soleimani’s killing, also urged patience on Wednesday, instructing his followers not to undertake any military action until all political avenues were exhausted to oust U.S. forces.

No group claimed responsibility for firing the two rockets that landed in the vicinity of the U.S. Embassy in Baghdad on Wednesday. But the militias have made clear they would avenge the killing of Mr. Mohandes, who had sought to centralize and consolidate control over the militias.

Mr. Khazali, whose Asaib Ahl al-Haq militia was designated a terrorist organization by the U.S. last week, denied involvement in Wednesday’s rocket attacks on the Green Zone, saying it could be the work of American intelligence. Separately, Jawad al-Tleibawi, a senior commander in the same group, told Iraq’s state news agency the rockets could be an individual act.

Mr. Tleibawi separately said the groups no longer used the kind of rockets that were fired into Baghdad’s Green Zone.

But he added that when it came, their response would be “very harsh.”

Laith Shobbar, an analyst and former adviser to Prime Minister Adel Abdul-Mahdi, said the rocket attacks might be the work of a smaller group seeking to prove itself. Since the killing of Messrs. Soleimani and Mohandes, several videos have emerged of small groups of armed men wearing black tactical gear declaring themselves a new resistance faction.

“The current weakness of the government is very helpful to such smaller groups to prove themselves by causing problems to others,” Mr. Shobbar said.

Write to Dion Nissenbaum at dion.nissenbaum@wsj.com and Isabel Coles at isabel.coles@wsj.com