After eight months of grinding urban warfare, Iraqi government troops on Thursday captured the ruined mosque at the heart of Islamic State's de facto capital Mosul, and the prime minister declared the group's self-styled caliphate at an end.