MOSUL, Iraq (AP) — The Iraqi intelligence agent knew something was wrong. An Islamic State group member working for him as an informant in the city of Mosul called him on his mobile, but he didn't identify himself by the code name they always used in their communications. Then the informant started talking to him about selling his car.

The agent played along.

Days later, the informant called back and explained: The militants had seen the number on his phone and, always on the hunt for spies, demanded he call it. So he did and pretended he was talking to the guy who sold him his car.

Iraqi intelligence has some 300 people working as informants inside the city of Mosul, part of an enormous information-gathering operation unfolding on the sidelines of the intense urban fighting for Mosul, according to officials. They have pinpointed militants' positions and movements, warned of car bombs or hidden explosives and helped fill a list of names of IS supporters.

The work is extremely dangerous.

IS militants in Mosul are known to kill at the slightest suspicion of espionage. People caught speaking on mobile phones have been shot by snipers or killed and hung from lampposts, according to accounts from the city. And when Iraqi forces recapture a neighborhood, informants face getting caught up in residents' revenge attacks against militants.

More than half a dozen Iraqi intelligence officials interviewed by The Associated Press described their operations. They said trust of the security forces among Mosul's residents has been key to their efforts. However, reports of long, arbitrary detentions of men and boys suspected of IS-links risks undermining that trust.

During the Mosul operation, intelligence agencies have built a database of some 18,000 names of suspected IS fighters, according to two Iraqi intelligence officials in Baghdad who have access to the database. Male residents of retaken parts of the city are checked against the list, leading so far to the arrest of 900 people, they said.

Story continues

All the officials spoke on condition of anonymity as they were not authorized to talk to the press. They also refused to give details on the informants for fear of endangering them.

The informants have a variety of motives. Some do it for money, since some agents pay for information.

Others do it out of hatred of IS. One operative was an Iraqi IS member who was beaten because he was caught smoking — a crime under the militants' rule.

"That was the first spark," said a Baghdad-based intelligence official in contact with the man. As time went on, the man grew disillusioned. So he started feeding information to intelligence officials.

Another is a 70-year-old man who escaped the militants' suspicions because of his age, the official said. But then after his neighborhood was retaken by Iraqi forces, neighbors blew up his house in anger at IS, unaware he was secretly betraying the group.

After months of fighting, troops have taken Mosul's eastern half and are about to move into the west. The intelligence gathering effort has been crucial there since Iraqi forces were under pressure for precision to avoid casualties among the hundreds of thousands of civilians still in the city.

On a recent day on the outskirts of Mosul, an Iraqi major involved in planning the western assault scrolled through messaging apps on his phone. The screen was filled with short texts, dropped pins and links to satellite maps. The messages read simply: "sniper position," ''mortar team," and "Daesh base," using the Arabic acronym for the militant group.

He and intelligence officials said they vet and cross-check information. Still, the process has been plagued with problems.

A colonel in the intelligence services in Baghdad said dozens of trusted informants have turned out to be double agents for IS. He recounted one case of one who provided information for weeks about fighters and headquarters behind IS lines. Last month, he sent in a tip about a roadside bomb.

The colonel vetted the tip and sent one of his men in Mosul to investigate. The soldier and the source were not heard from again.

"We think the source handed him over to Daesh," he said.

Another intelligence official said he knew of some half dozen informants discovered and killed by IS and still more who stopped sending information, their fate unknown.

Key to success has been the concerted effort by security forces to keep support of Mosul's Sunnis, who have resented domination by the Shiite-led government in Baghdad. They long complained of discrimination and of abuses by security forces, something that helped fuel the rise of the Islamic State group. During the Mosul offensive, troops have gone out of their way to help residents and prevent sectarian tensions.

On a recent operation in eastern Mosul, Lt. Col. Muhanad al-Timimi and his men were greeted warmly by residents of the Andalus neighborhood. They went door to door asking about IS militants.

One resident, Muhammed Ghanim, led the soldiers to a house with a pile of mortars in the garden. "This was where they had their base," he said.

Another, Amar Baroudi, gave the soldiers tea — and names of more than 20 Iraqis fighting for IS.

"These people were ignorant and very cruel to us." he said of the militants. "Now I'm proud to help the security forces find them and punish them."

That goodwill can be easily strained.

Human Rights Watch says it has information indicating thousands have likely been arrested in the Mosul operation. The vast majority have not been allowed to access a lawyer or inform their families where they are, said Belkis Wille, the senior Iraq researcher for HRW.

Wille said initially families from Mosul who had a loved one detained by Iraqi forces trusted they would quickly be screened and released, but as months dragged on with no news, that mood is changing.

"They had this window to regain the trust," Wille said, "but they're losing that opportunity."

___

Abdul-Zahra reported from Baghdad.