WASHINGTON—President Barack Obama said Thursday he was dropping plans to withdraw nearly all American troops from Afghanistan, reversing his long-held intention to exit the conflict before the end of his administration.

Mr. Obama said the U.S. will maintain the current American force of 9,800 troops in Afghanistan through most of next year and keep at least 5,500 U.S. troops in the country after he leaves office in January 2017.

His...