American and allied forces have vacated their final bases in Iraq, concluding anti-Islamic State operations and ending more than two decades of direct military engagement.