By Maher Chmaytelli and Isabel Coles

ERBIL, Iraq (Reuters) - It was barely more than a squiggle, but the mark of a single letter sprayed overnight on a wall in the heart of Islamic State's self-proclaimed caliphate was a daring act of dissent.

The next day, ultra-hardline Islamic State fighters came and scrubbed out the "M" -- the first letter of the word for "resistance" in Arabic -- which appeared in an alley near the Grand Mosque in the Iraqi city of Mosul about three weeks ago.

A video of the single letter, scrawled about a meter long on the wall, was shared with Reuters by an activist from a group called "Resistance", whose members risk certain execution to conduct small acts of defiance in areas under Islamic State rule.

Nearly two years since Islamic State leader Abu Bakr al-Baghdadi delivered a sermon from that same mosque summoning Muslims worldwide to the "caliphate", it is fraying at the edges.

As an array of forces make inroads into their territory spanning Iraq and Syria, the jihadis are becoming even harsher to maintain control of a population that is increasingly hostile to them, according to Iraqi officials and people who managed to escape.

"They are harsh, but they are not strong," said Major General Najm al-Jubbouri, who is in command of the operation to recapture Mosul and the surrounding areas. "Their hosts reject them."

Many local Sunnis initially welcomed the Sunni Muslim militants as saviors from a Shi'ite-led government they perceived as oppressive, while thousands of foreigners answered Baghdadi's call to come and wage holy war.

For a time, the militants claimed one victory after another, thanks as much to the weakness and division of the forces arrayed against them as their own strength. They funded themselves through sales of oil from fields they overran, and plundered weapons and ammunition from those they vanquished.

But two years since the declaration of the caliphate, the tide has begun to turn in favor of its many enemies: Iraqi and Syrian government troops, Kurdish forces in both countries, rival Syrian Sunni rebels, Iranian-backed Shi'ite militias, and a U.S.-led coalition which has bombed the militants while conducting special operations to take out their commanders.

Of the 43 founders of Islamic State, also known as ISIS, ISIL or Daesh, 39 have been killed, said Hisham al-Hashimi, a Baghdad-based expert who advises the Iraqi government.

The self-proclaimed caliph, Baghdadi, is moving in a semi-desert plain that covers several thousand square kilometers west of the Tigris river and south of Mosul, avoiding Syria after two of his close aides were killed there this year: "war minister" Abu Omar al-Shishani and top civilian administrator and second-in-command Abd al-Rahman al-Qaduli, Hashimi said.

The most senior commanders after Baghdadi are now Abu Mohammed al-Adnani, the group's spokesman who took over military supervision after Shishani's death, and Abu Muhammad al-Shimali, who oversees foreign fighters and succeeded Qaduli as civilian administrator, he said.

Kurdish and Iraqi military commanders say the group is deploying fighters who are less experienced and less ideologically committed to defend what remains of its quasi-state, which is under attack on multiple fronts.

Iraqi forces recently entered the Islamic State bastion of Falluja just west of Baghdad, and are pushing north towards Mosul, by far the biggest city Islamic State controls with a pre-war population of 2 million.

In neighboring Syria, U.S.-backed forces are closing in on the militant stronghold of Manbij, and President Bashar al-Assad's Russian-backed army has advanced into the province surrounding the de facto Islamic State capital Raqqa.

On a front south of Mosul, a group of women displaced by the offensive said Islamic State fighters' grip had begun to loosen as Iraqi forces advanced, to the point that they no longer punished people for not wearing the full face veil.

The number of foreign fighters has fallen significantly, and renewed efforts by the group to recruit locals have proven largely unsuccessful, except amongst the young and destitute, according to people who recently fled, including three repentant Islamic State members.

"When you are a young man and you don't own 250 dinars and someone comes and offers you 20,000, 15,000 or 30,000, you will do anything," said a former Islamic State militant from Iraq's northern Hawija district who recently gave himself up to Kurdish forces.

Members of Islamic State's vice squad, the Hisba, are increasingly being sent to the frontlines as designated fighters are killed off, according to people who escaped as well as Iraqi and Kurdish military and intelligence officials.

That means there are fewer militants to enforce the group's draconian rules and dress code. But a 28 year-old teacher who recently fled Mosul said people were so afraid of the militants they did not disobey them even when they were not around.

"If they say black is white, you agree," said the teacher, who asked not to be identified because he still has family inside the city and feared they could be targeted.

School courses were redesigned by the militants to reflect their war-like ideology. He gave an example of a math problem given to his pupils: "The Mudjahid is carrying seven magazines for his rifle, each with 30 bullets; how many rounds can he fire at the unbelievers?"

He said Arabic lessons were also redesigned, with pupils asked to fill in blanks in slogan-like sentences such as "The Islamic State is xxxx and xxxx". The answer is "staying and expanding".

ASSET AND LIABILITY

The Sunni population in which the militants have embedded themselves is becoming more of a liability to them but also remains one of their greatest assets.

As living conditions deteriorate and the militants crack down, the local population is increasingly hostile to the group, which has repeatedly used civilians as human shields to slow the advance of Iraqi forces in frontline cities like Falluja.

Those caught trying to escape Islamic State territory are liable to be executed on the spot -- even women and children.

Despite outnumbering the militants, the population remains weaker than them. Residents were disarmed and the security forces purged in the early days after the fighters captured Mosul. But residents are increasingly cooperating with the security forces outside the city by informing on the militants.

Nineveh provincial council member Abdul Rahman al-Wakaa said the group had begun moving local leaders around so people could not identify them as easily and pass their location on to coalition and Iraqi forces.

The jihadis have also cracked down on communications with the outside world, executing people for using mobile phones and confiscating satellite dishes to prevent people from seeing the progress made by Iraqi forces.

Iraqi military leaders are hoping there will be an uprising against the insurgents as the army draws nearer to Mosul. A top Iraqi general told Reuters troops were in contact with people inside Mosul to synchronize such action with an external military assault.

The plan is to engage the militants on several fronts around Mosul simultaneously, to draw them out of the city, giving the local population a chance to revolt.

Acute hardship and hunger since Baghdad cut salaries to state workers living in areas under Islamic State control around a year ago has forced more locals to work for the group.

Islamic State, for its part, plays on the population's fears of retribution from Iraqi forces and pro-government Shi'ite militias. Despite a string of defeats, military officials say there have been few defections from the group.

Three young men who joined Islamic State and recently surrendered to Kurdish forces in northern Iraq said the militants hunted down those who tried to abandon them.

Ahmed Ibrahim Abdullah said he had been arrested and tortured by the militants when he left. He sold a cow to pay for his bail so he could escape.

Twenty-six year old Ahmed Khalaf said he had surrendered to the Kurds in the hope he would be treated with more leniency than if captured by government forces, but that others were too afraid to the same: "There are people who have a certain idea that their fate is tied to the fate of Daesh."

(Editing by Peter Graff)