CAIRO, Egypt — The video, set to sweetly lilting religious hymns, is chilling. Islamic militants are shown knocking on the door of a Sunni police major in the dead of night in an Iraqi city. When he answers, they blindfold and cuff him. Then they carve off his head with a knife in his own bedroom.

The 61-minute video was recently posted online by the Islamic State of Iraq and the Levant, an al-Qaida splinter group of Sunni extremists. The intent was clearly to terrorize Sunnis in Iraq’s army and police forces and deepen their already low morale.

That fear is one factor behind the stunning collapse of Iraqi security forces when fighters led by the Islamic State overran the cities of Mosul and Tikrit this week, sweeping over a swath of Sunni-majority territory. In most cases, police and military simply ran, sometimes shedding uniforms, and abandoned arsenals of heavy weapons.

Even after the United States spent billions of dollars training the armed forces during its 2003-2011 military presence in Iraq, the 1 million-member army and police remain riven by sectarian discontents, corruption and a lack of professionalism.

Many Sunnis in the armed forces are unprepared to die fighting on behalf of Prime Minister Nouri al-Maliki’s Shiite-led government, which many in their minority community accuse of sharp bias against them. The Islamic State has exploited this by touting itself as the Sunnis’ champion against Shiites.

Shiites in the armed forces, in turn, feel isolated and deeply vulnerable trying to hold on to Sunni-majority areas.

Desertion has been heavy the past six months among forces in the western province of Anbar, Iraq’s Sunni heartland, where troops have been fighting in vain to uproot Islamic State fighters who took over the city of Fallujah, said two high officials — one in the government and the other in the intelligence services.

The militants who early this week swept into the northern city of Mosul included former Sunni army officers who had deserted out of frustration with al-Maliki’s government, the two officials told The Associated Press, speaking on condition of anonymity to discuss intelligence reports.

As the militants approached, the two officials said, many of the top army commanders in Mosul, Iraq’s second largest city, fled to the autonomous Kurdish region.

With their generals gone, the ranks saw no reason to stay.

“We were fighting but our leaders betrayed us,” one soldier who escaped from Mosul told the AP in Irbil, capital of the Kurdish region. “When we woke up, all the leaders had left.”

The intelligence assessments show that many of the 52,000 police and 12,000 soldiers in Mosul surrendered, handing over their weapons in exchange for safe passage out, the two officials said.

With a salary of $700 a month for newly enlisted men, the army and the police have attracted many young Iraqis who would otherwise be unemployed. Once in, some bribe commanders so they can stay home and take a second job, lamented the officials.

Most are in it for the paycheque. “There’s a sense the individuals looked to themselves and thought this is not my fight,” said Feisal Istrabadi, a former Iraqi ambassador to the United Nations. “They haven’t been trained and imbued with a sense of professionalism.”

“Even in the army, the loyalties are not to the state,” said Istrabadi, now director of the Center for the Study of the Middle East at Indiana University.

Many troops are drawn from the ranks of Shiite militiamen and from Sunni tribal militias, known as the Sahwa, set up by the Americans to fight al-Qaida. The loyalties of those troops are often more to their sect or tribe than to the state. In Baghdad, army checkpoints manned by Shiite troops often fly Shiite banners or images of Shiite religious figures.

With most soldiers lacking training and discipline, offensive operations are mostly carried out by a special, U.S.-trained counterterrorism outfit of some 10,000 men that fought alongside the Americans for years, the two officials said.

But that unit, they said, does not have the manpower to hold territory after it drives militants out. So it hands the task over to regular troops, who then surrender it again when under fire.

The counterterrorism unit is under al-Maliki’s direct authority, and there is discontent among officers in the regular military that the prime minister weighs in too heavily on military matters. Another source of low morale among the ranks is widespread corruption in military contracts that end up with troops receiving poor supplies and food.

The two officials said the security forces’ incompetence will very likely force al-Maliki to rely increasingly on hard-line Shiite militias, some of which are loyal to Iran, in the fight against the Islamic State.

That would only further deepen the shadow that sectarianism casts over Iraq and its armed forces.

The Sunni minority that dominated power under dictator Saddam Hussein resents the political ascendancy of the Shiite majority since his 2003 ouster in the U.S.-led invasion. The two communities came close to outright civil war in 2006-2008, with tens of thousands killed in almost daily massacres and bombings.

Sunnis are well represented in the military’s officer corps. The majority of soldiers and warrant officers are Shiites, but they mostly serve in areas dominated by members of the same sect. That leaves the Sunnis to serve in Sunni areas like Mosul and Anbar, where many of them are demoralized by the idea of fighting against fellow members of their Muslim sect.

Police forces are usually drawn from local populations and so are particularly vulnerable to intimidation.

The harrowing video put out 10 days ago by Islamic State’s media arm, Al-Furqan, underscores the threats to Sunnis in pro-government forces.

Speaking on condition of anonymity for fear of reprisals, Iraqis contacted in Anbar and the provinces where Mosul and Tikrit are located said the video was widely seen. They spoke of people they knew personally who deserted the military after watching the footage of the summary execution.

One resident of Fallujah, identifying himself only by his nickname Abu Ali, said the video brought home the Islamic State’s brutality. But he said morale is already low among troops because of almost daily attacks by jihadis on army positions. “The strikes by fighters in the streets had more effect than the video,” he said.

Besides the scene of the beheading of the Sunni police major in Salaheddin province, the video includes footage of drive-by shootings of off-duty security personnel and the execution of captured army soldiers. In one scene, fighters masquerading as soldiers set up a checkpoint on a main highway, stopping cars and executing Shiites and security personnel by the side of the road.

In another horrifying scene, fighters abduct a Sahwa commander along with his two sons. They are forced to dig their own graves in the desert before their throats are slit.

“I advise whoever is with the Sahwa to repent and quit,” the commander says to the camera. “Here I am digging my grave with my own hands. … They can get to anyone.”

Mroue reported from Beirut. Associated Press writers Qassim Abdul-Zahra in Beirut and Adam Schreck in Dubai, contributed to this report.