BAGHDAD — Sunni Arab guerrillas ambushed an American convoy in the northern city of Mosul with a roadside bomb Monday and sprayed survivors with machine-gun fire from perches in a nearby mosque, killing five U.S. soldiers.

It was the second devastating attack on U.S. forces this month, bringing the number of fatalities to 36 this year, and the latest sign that the main front of the insurgency has shifted to northern Iraq.

While American fatalities have fallen sharply in Baghdad and Anbar province, they have not slowed in the north. Three-fifths of the American servicemen killed this year were in three Sunni Arab-dominated provinces north of Baghdad. Three weeks ago, a house rigged with explosives killed six soldiers in Diyala province.

The attack Monday underscored the grim situation in Mosul, Iraq's northern hub, which remains a stronghold for Sunni extremist fighters. The Americans fought back and sent Iraqi soldiers to raid the mosque, but the gunmen had already fled, American military officials said.

Under pressure to show firmness against the insurgency, Prime Minister Nouri Kamal al-Maliki pledged last week to begin a "decisive" battle against militants in Mosul.

He made that promise after a powerful blast shook the city last Wednesday as Iraqi soldiers entered a building packed with explosives. The Iraqi Red Crescent Organization reported that at least 60 people had been killed and 280 wounded, mostly children, women and the elderly.

The attack enraged residents, who were furious at government leaders for failing to protect them. The next morning, when the provincial police chief visited the site, he was stoned by a crowd of angry people who had been digging bodies of relatives from the rubble. As he tried to leave, he was assassinated by a suicide bomber.

Iraqi officials have said they are massing troops and equipment in Mosul, but they have disclosed little information about what they plan to do. American military officials say they are not expecting significant new operations, but more focused coordination between the Iraqi police and army.

The gunmen who attacked the convoy Monday had been holed up in the Sunni Yarimjah mosque in southern Mosul, said Maj. Gary Dangerfield, a military spokesman. He said troops were continuing to conduct operations into the night in the surrounding area in pursuit of the guerrillas, who he said "have no respect for Islam, for the people of Iraq or for the holy sites" in Mosul.