BAGHDAD  An assault by thousands of Iraqi soldiers and police officers to regain control of the southern port city of Basra stalled Wednesday as Shiite militiamen in the Mahdi Army fought daylong hit-and-run battles and refused to withdraw from the neighborhoods that form their base of power there.

American officials have presented the Iraqi Army’s attempts to secure the port city as an example of its ability to carry out a major operation against the insurgency on its own. A failure there would be a serious embarrassment for the Iraqi government and for the army, as well as for American forces eager to demonstrate that the Iraqi units they have trained can fight effectively on their own.

During a briefing in Baghdad on Wednesday, a British military official said that of the nearly 30,000 Iraqi security forces involved in the assault, almost 16,000 were Basra police forces, which have long been suspected of being infiltrated by the same militias the assault was intended to root out.

The operation is a significant political test for Prime Minister Nuri Kamal al-Maliki, who traveled to Basra to oversee the beginning of the assault. It is also a gamble for both the Iraqi and American governments. The Americans distrust the renegade cleric Moktada al-Sadr and his Mahdi Army militia, who consider the Americans occupiers.