BAGHDAD — Five American soldiers died Monday when a barrage of rockets slammed into a base in a Shiite neighborhood of eastern Baghdad – the largest, single-day loss of life for U.S. forces in Iraq in two years.

The attack follows warnings from Shiite militants backed by Iran and anti-American cleric Muqtada al-Sadr that they would violently resist any effort to keep American troops in Iraq past their year-end deadline to go home.

Although American casualties have dropped considerably in the two years since U.S. troops pulled back from Iraq cities, Shiite militias have begun hammering U.S. bases and vehicles with rockets, rocket-propelled grenades and roadside bombs over the past three months.

The militants’ goal appears twofold: to give the impression that they are driving the withdrawing U.S. forces out of Iraq, and to make the U.S. think long and hard before agreeing to any Iraqi request to keep a contingent of troops in this country beyond the end of the year.

“Iranian-backed militias are flexing their muscles and have steadily increased military pressure on U.S. forces since rumors first started in the early spring concerning an extension of the U.S. presence,” said Michael Knights, an Iraq analyst at the Washington Institute.

Washington has been pressuring Baghdad to make a decision on whether it wants American forces to stay past Dec. 31 to help with such missions as protecting Iraq’s airspace and training Iraqi forces.

Although few Iraqis will say this in public, many feel their own security forces are ill-equipped to keep a lid on violence and secure their borders without the assistance of the Americans.

Violence around Iraq has dropped dramatically since the insurgency’s most deadly years in 2006 and 2007.

But eight years into a war often perceived as all but over, the deaths of the five U.S. soldiers and 11 Iraqis killed in other attacks around the country Monday underscore the persistent dangers here.

The violence also shows the threat Iranian-backed militias pose to U.S. forces if they stay longer and the potential backlash that Iraqi political leaders face if they support an extension.