Iraq's premier fired several top security commanders in a major shake-up on Tuesday as fighting approached Baghdad in a militant onslaught that the UN warned risked breaking up the country.
Washington deployed some 275 military personnel to protect its embassy in Baghdad, the first time it has publicly bolstered the mission's security.
And it was also mulling air strikes against the militants, who are led by the jihadist Islamic State of Iraq and the Levant (ISIL) but include loyalists of now-executed Sunni Arab dictator Saddam Hussein.
A relative calm in Baghdad was shattered by a string of bombings that left 17 people dead, while the bodies of 18 soldiers and police were found near the city of Samarra, shot in the head and chest.
More than a week after insurgents launched their lightning assault, Prime Minister Nuri al-Maliki dismissed several senior officers, including the commander for the northern province of Nineveh, the first to fall.
Maliki also ordered that one of them face court-martial for desertion.
The dismissals came after soldiers and police fled en masse as insurgents swept into Nineveh's capital Mosul, a city of two million, abandoning their vehicles and uniforms.
As officials trumpet a counter-offensive, doubts are growing that Iraq's security forces can hold back the tide.
However Pentagon spokesman Rear Admiral John Kirby said Iraqi troops, with help from Shiite volunteers, were "stiffening their resistance" around Baghdad.
"It certainly appears as if they have the will to defend the capital," he said.
After taking Mosul, militants captured a major chunk of mainly Sunni Arab territory stretching towards the capital.
The offensive has displaced hundreds of thousands of people and sent jitters through world oil markets as the militants have advanced ever nearer to Baghdad, leaving the Shiite-led government in disarray.
Officials said Tuesday that militants briefly held parts of the city of Baquba, just 60 kilometres (40 miles) from the capital.
They also took control of most of Tal Afar, a strategic Shiite-majority town between Mosul and the border with Syria, where ISIL fighters are engaged in that country's three-year-old civil war.
The overnight attack on Baquba, which was pushed back by security forces but left 44 prisoners dead at a police station, marked the closest the fighting has come to the capital.
In Tal Afar, militants controlled most of the town but pockets of resistance remained.
Further south, security personnel abandoned the Iraqi side of a key crossing on the border with Syria, officers said.
Syrian rebels opposed to ISIL were then able to seize the Iraqi side of the Al-Qaim crossing as well.
Elsewhere, an Iraqi cameraman was killed and a correspondent wounded while covering the unrest, their television channel said.
'Life-threatening for Iraq'
The swift advance of militants has sparked international alarm, with UN envoy to Baghdad Nickolay Mladenov warning that Iraq's territorial integrity was at stake.
"Right now, it's life-threatening for Iraq but it poses a serious danger to the region," Mladenov told AFP.
"Iraq faces the biggest threat to its sovereignty and territorial integrity" in years.
The violence has stoked regional tensions, with Iraq accusing neighbouring Saudi Arabia Tuesday of "siding with terrorism" and of being responsible for financing the militants.
The comments came a day after the Sunni kingdom blamed "sectarian" policies by Iraq's Shiite-led government for triggering the unrest.
The prime minister of Iraq's autonomous Kurdish region told the BBC it would be "almost impossible" for the country to return to how it was before the offensive, and called for Sunni Arabs to be granted an autonomous region of their own.
Senior Sunni and Shiite political leaders, including Maliki and his rival parliament speaker Osama al-Nujaifi, jointly issued a televised statement pledging continuous dialogue and promising to preserve the country's unity.
Alarmed by the collapse of much of the security forces in the face of the militant advance, foreign governments have begun pulling out diplomatic staff.
US President Barack Obama announced that around 275 military personnel "equipped for combat" were being deployed to Iraq to help protect the embassy in Baghdad and assist US citizens.
Washington has already deployed an aircraft carrier to the Gulf, but Obama has ruled out a return to combat in Iraq for US soldiers.
As the US weighed its next move, Secretary of State John Kerry said Monday that drone strikes could be used.
Washington has ruled out cooperating militarily with Iran, but the two governments -- which have been bitter foes for more than 30 years -- held "brief discussions" in Vienna on the crisis.
The jihadists are said to have killed scores of Iraqi soldiers as they pushed their advance, including in a "horrifying" massacre in Salaheddin province that has drawn international condemnation.
Top Shiite cleric Grand Ayatollah Alal-Sistani has called for volunteers to join the battle against the militants and thousands have signed up.
Some have returned home from neighbouring Syria, where they had been fighting alongside government forces against mainly Sunni rebels there, a monitoring group said.