BAGHDAD — The mourners came by the thousands, flooding the streets of a city that is no stranger to violence. But this time, there was a different edge. The fear was more acute, the potential repercussions more ominous.

Iraq's funeral procession for Maj. Gen. Qasem Soleimani, the Iranian commander killed in a U.S. airstrike early Friday, started early and lasted hours. Men in Baghdad wept openly near his coffin, and — like leaders in Iran — vowed revenge for his death.

The attack has shaken Iraq, sharpening long-standing fears that the country’s soil will become home, again, for a bloody shadow war between Washington and Tehran. For many caught in between, Baghdad now carries echoes of the uncertainties that preceded the 2003 U.S.-led invasion.

Iraq’s powerful Shiite militias are aligned with Iran against U.S. forces and, at times, against their Iraqi allies as well.

More than any other nation, Iraq has for years been the staging ground for tit-for-tat strikes between Iran and the United States. Other than Soleimani’s funeral procession on Saturday, the streets of Baghdad were nearly deserted.

Iraqis stayed home, watched the news and prayed that, this time, they would be spared.

But the chants from the funeral cortege signaled looming confrontation.

“Death to America! Death to Israel!” mourners cried, following the bodies of Soleimani and Abu Mahdi al-Muhandis, a powerful Iraqi militia leader. “We will take our revenge!”

Mourners waved Iraqi flags and the banners of paramilitary forces backed by Iran and known collectively as the Hashd al-Shaabi. As the mourners set out from the Baghdad neighborhood of Kadhimiyah, officials from Iraq and Iran, along with militia leaders, were seen making their way through the throngs flanked by guards.

Iran has vowed to retaliate against the United States for the killing of Soleimani, Tehran’s most powerful military commander, and the Trump administration has said it is sending thousands of additional troops to the Middle East. The confrontation has left the region bracing for a sharp escalation of violence — with Iraq possibly at the center of the storm.

Within the past week, Baghdad’s heavily fortified Green Zone was the site of chaos, as supporters of an Iran-backed militia surrounded the U.S. Embassy and pelted it with rocks and flaming gasoline bombs.

On Saturday, the area was locked down. The country’s elite counterterrorism forces fanned out in black vehicles down the four-square-mile strip of land along the Tigris River. At the U.S. Embassy, Marines stood guard on the rooftops, two diplomatic officials said, speaking on the condition of anonymity to discuss security issues.

“There’s no smiling,” one military official said.

U.S. helicopters circled above the Green Zone. Several miles away at Soleimani’s funeral, Iraqi helicopters did the same, monitoring the area and scanning for threats. In southern Iraq, oil companies said that American citizens had packed their bags and left.

As night fell, officials in the Green Zone and at Balad air base, north of the capital, reported that at least one rocket had landed near each facility. Iran-backed militias have been attacking U.S.-supported forces for months.

U.S. officials said the catalyst for the drone strike on Soleimani’s two-car convoy was a rocket attack in Kirkuk; it killed an American contractor there and wounded several others.

A spokesman for the U.S.-led military coalition against the Islamic State said Saturday that it had “increased security and defensive measures at the Iraqi bases that host anti-ISIS coalition troops. Our command places protection of U.S. forces, as well as our allies and security partners in the coalition, as the top priority; we remain vigilant and resolute.”

One State Department official serving at the embassy described the atmosphere as “surreal” as the skeleton crew of U.S. officials working in the compound tried to stay productive amid the heightened security threat.

The embassy has been operating with fewer people since May when non-emergency personnel were ordered to depart because of specific but unnamed threats. The staffing situation was worsened by the holidays as diplomats left for the United States and now cannot return because of the security risks.

Many officials at the embassy remain busy with diplomatic duties, especially given the absence of local staff. Diplomats are dipping into their own supplies of liquor and wine, said two officials in Baghdad who spoke on the condition of anonymity to discuss internal matters.

One senior administration official said Secretary of State Mike Pompeo has no plan to evacuate the embassy at this point, given his view that the work of U.S. diplomats in the country is more important than ever and concerns that a mass exit would be viewed as a retreat in the face of Iranian intimidation.

NATO, which has several hundred workers in Iraq, said Saturday that it has temporarily suspended its training of Iraqi forces to counter the Islamic State, according to Dylan White, an organization spokesman.

“The safety of our personnel in Iraq is paramount. We continue to take all precautions necessary,” he said in an emailed statement.

The Pentagon said Friday that it was preparing to deploy an additional 3,500 soldiers from the 82nd Airborne Division to the region. According to two defense officials, the military also has put hundreds of soldiers from the Army’s 173rd Airborne Brigade in Italy on alert for potential deployment.

Abdul-Karim Khalaf, a security spokesman for Iraq’s prime minister, said authorities were investigating crew members who were on the aircraft that brought Soleimani to Baghdad — reportedly from Damascus — apparently to determine how the United States had learned of the Iranian commander’s whereabouts.

Khalaf, speaking to Iraq’s state news agency, reiterated that U.S. forces are not allowed to conduct military operations in Iraq without the approval of the prime minister, and he hinted that their future in the country is in doubt.

“We have alternatives to train our armed forces,” Khalaf said.

As the heavily guarded procession made its way through Jadriyah, in central Baghdad, trailed by residents and soldiers, cars outfitted with loudspeakers provided a soundtrack that mixed political commentary and angry slogans.

When the funeral convoy stopped for a moment, a man was seen clutching the side of a flatbed truck and weeping, seemingly oblivious to the cacophony around him.

“America will pay a heavy price!” one man yelled. Iraq’s parliament, he said, should expel U.S. forces.

Another man in the crowd disagreed. The Americans should stay in Iraq, he thought, “so we can bury them here.”

Loveluck reported from Beirut and Fahim from Istanbul. Missy Ryan and John Hudson in Washington contributed to this report.