BAGHDAD -- Militants launched an attack on a Sunni-dominated city north of Baghdad on Thursday, killing seven members of the Iraqi security forces and setting off a day-long battle that eventually forced them to retreat from the city.

The assault on Samarra, 95 kilometres (60 miles) from Baghdad, started with dozens of gunmen driving into the city in the morning in SUVs, attacking security checkpoints and police stations and taking control of some areas of the city for hours, officials said.

Reinforcements were sent in and local authorities imposed a curfew as helicopter gunships bombed militant positions. By sunset, the gunmen were forced to withdraw from Samarra and smaller clashes were taking place on the city's outskirts, the police said.

Local hospital officials said that apart from the seven policemen and soldiers killed, several attackers also died.

No one immediately claimed responsibility for the attack.

Samarra was the scene of a major turning point in the Sunni-Shiite sectarian struggle in Iraq following the 2003 U.S.-led invasion. In 2006, the then al-Qaida-linked Sunni insurgents bombed the city's revered Shiite al-Askari shrine, triggering a wave of sectarian violence that brought Iraq to the brink of civil war.

Thursday's attack on Samarra comes against the backdrop of major clashes in Iraq's western Anbar province, where government forces and allied Sunni tribal militiamen have been trying since late December to dislodge militants from two key cities, the provincial capital of Ramadi and nearby Fallujah.

The militants, mainly from the al-Qaida splinter group known as the Islamic State in Iraq and the Levant, have seized parts of Ramadi and most of Fallujah.

In months-long fighting, the government has not made significant progress in its campaign to defeat the militants in Anbar.

The militants -- empowered by fellow Sunni fighters' gains in the civil war in neighbouring Syria and exploiting the Iraqi Sunnis' anger over perceived discrimination at the hands of the Shiite-led government -- have escalated attacks in Iraq since last year, with violence surging to levels not seen since 2006 and 2007.

In other violence Thursday, a bomb blast near a bakery in a town just south of Baghdad killed two people and wounded 10, police and hospital officials said. In eastern Baghdad, a bomb exploded near a bus stop, killing one person and wounding eight.

Hospital officials confirmed the casualty figures. All officials spoke on condition of anonymity because they were not authorized to talk to media.

According to U.N. figures, 8,868 people were killed in Iraq in 2013. The U.N. mission said that May was the deadliest month so far this year, with 799 Iraqis killed in violence, including 603 civilians.