The attack, which was claimed by the Islamic State group, sowed panic among residents who returned to live in the Tanak.
The attack, which was claimed by the Islamic State group, sowed panic among residents who returned to live in the Tanak and Yarmuk neighbourhoods of west Mosul.
A top commander in the Counter-Terrorism Service (CTS), which sent forces to fight the IS gunmen, said the attackers had infiltrated the area by blending in with returning displaced civilians.
"The group came with the displaced and settled in the Tanak district. They regrouped and launched counter-attacks," Staff Lieutenant General Abdulwahab al-Saadi told AFP.
"Yarmuk is being searched house to house," he said, adding that two groups of IS attackers were still believed to be in the area, which lies on the western edge of the city.
A CTS medic said the attack had caused several victims but he could not say how many.
"There are martyrs who were killed by Daesh," the medic said, using an Arabic acronym for IS.
He said 15 to 20 jihadist fighters were also killed in the battle.
Iraqi forces, led by the CTS, have for a week been pressing a perilous assault into the Old City in central Mosul, the last pocket still controlled by the jihadists.
Federal forces backed a US-led coalition launched an offensive to retake the country's second city from IS more than eight months ago.
The east bank of Mosul, a city divided by the Tigris River, was retaken in January and a push to wrest back the western side was launched in mid-February.
More than 800,000 people have been displaced from the Mosul area since October last year and the security forces are struggling to carry out effective screening.
While the exact circumstances were unclear, Sunday night's attack was described as a diversionary tactic by west Mosul "sleeper cells" to ease the pressure on the Old City, where the jihadists appear to be on their last legs.
"The sleeper cells carried out a surprise attack against the security forces, in an attempt to ease the siege on the Old City," a local official told AFP on condition of anonymity.
"Operations to flush out pockets controlled by Daesh are ongoing," he said.
Hundreds of families, who in some cases had returned to their homes weeks ago, fled the area again overnight, fearing the return of jihadist rule.