With just two hours notice, Prime Minister Nouri al-Maliki ordered everyone off the streets of the capital from 2 p.m. until 5 p.m.
Iraqi and U.S. military forces clashed throughout the morning with attackers carrying rocket-propelled grenades, hand grenades and rifles in busy Haifa Street, which runs into the Green Zone, site of the U.S. and British embassies and the Iraqi government.
Four Iraqi soldiers and three policemen were wounded, police Lt. Maitham Abdul Razzaq said.
The area was sealed and Iraqi and U.S. forces conducted house-to-house searches.
The fighting was unusual in its scope and intensity. There have, however, routinely been clashes along Haifa Street, making it so dangerous that a sign at one Green Zone exit checkpoint warns drivers against using it.
U.S. and Iraqi forces also fought gunmen in the volatile Dora neighborhood in south Baghdad.
Two U.S. soldiers were killed when a roadside bomb struck their vehicle southeast of the capital, the U.S. military said.
The military also said two U.S. Marines died in combat in volatile Anbar province in separate attacks on Wednesday and Thursday, and a soldier died elsewhere in a non-combat incident on Wednesday.
At least 2,517 members of the U.S. military have died since the Iraq war started in March 2003, according to an Associated Press count.
In other recent developments:
Also Friday, a car bomb ripped through a market and nearby gas station in the increasingly violent southern city of Basra, killing at least five people and wounding 18, including two policemen, police said.
A bomb also struck a Sunni mosque in Hibhib, northeast of Baghdad, killing 10 worshippers and wounding 15 in the town where Abu Musab al-Zarqawi was slain this month, police said. The area is the scene of frequent sectarian violence and there was no apparent connection to al-Zarqawi's killing.
At least 19 other deaths were reported in Baghdad.
The prime minister's office at first said the curfew would last until 6 a.m. Saturday but then shortened it.
The state of emergency includes a ban on carrying weapons and gives Iraqi security forces broader arrest powers, Defense Ministry official Maj. Gen. Abdul-Aziz Mohamed Jassim said.
"The state of emergency and curfew came in the wake of today's clashes to let the army work freely to chase militants and to avoid casualties among civilians," he said. "They will punish all those who have weapons with them and they can shoot them if they feel that they are danger."
Gunmen also attacked a group of worshippers marching from Sadr City, the Shiite slum in eastern Baghdad, to the Buratha mosque on the other side of the city to protest a suicide attack a week ago on the revered Shiite shrine. At least one marcher was killed and four were wounded, Lt. Ahmed Mohammed Ali said.
Al-Maliki has been trying to rein in unrelenting insurgent and sectarian violence. He launched a massive security operation in Baghdad 10 days ago, deploying tens of thousands of troops who flooded the city, snarling traffic with hundreds of checkpoints.
Police said they found the bodies of five men who apparently were victims of a mass kidnapping from a factory on Wednesday. The bodies, which showed signs of torture and had their hands and legs bound, were floating in a canal in northern Baghdad, police Lt. Maitham Abdul-Razzaq said.
A police raid on a farm Thursday freed 17 of the captives
Meanwhile, the U.S. military said it killed four foreign insurgents in a raid north of Fallujah. Two of the dead men had 15-pound bombs strapped to their bodies. The military said an insurgent thought to be an Iraqi also was killed in the raid, which was launched on the basis of information from a suspected arrested in the region in previous days.
Separately, the military said, it detained a senior leader of al Qaeda in Iraq and three other suspected insurgents Monday during raids northeast of Baghdad, near where al-Zarqawi was killed in a U.S. air raid earlier this month.