BAGHDAD — The United States military officially declared an end to its mission in Iraq on Thursday even as violence continues to plague the country and the Muslim world remains distrustful of American power.