We fought a war against muslim extremists in the Philippians from 1899-1904. That war was almost like Iraq. After major operations, the military declared victory. Soon after Americans were dying in attacks. The key factor in winning that war was winning over the people. US troops set up schools, improved roads, provided governmenr services and treated prisoners extremely good. Soon, the locals realized that life was better with the Americans.
While we may be doing those things now in Iraq, we did not do so in the begining. After the war ended, I felt we sat around for a few months while we impoved our living conditions but not those of the Iraqis. Then there is Abu Ghraib. If you want to learn more, check out the Marines Small wars manual.