Credit: Nicholas Kamm/AFP/Getty Images President Barack Obama said Wednesday that there will be 8,400 troops in Afghanistan when he leaves office, an increase from a previous announcement that there would be 5,500.

WASHINGTON -- President Barack Obama again stalled the withdrawal of troops from Afghanistan, announcing on Wednesday that he plans to keep 8,400 American troops there through the remainder of his presidency. Prompted by continued Taliban gains and the threat of an Islamic State stronghold in the country, the move is a departure from his previous plan to decrease the current level of nearly 10,000 troops to 5,500 by the end of 2016.

In an appeal to a war-weary population that has grown cynical of a seemingly endless war in Afghanistan, Obama listed a series of successes of the U.S. effort there: the death of Osama bin Laden, a weakened al-Qaeda presence, the withdrawal of 90 percent of American troops, and the fact that Afghan security forces now control major population centers.

“Nevertheless, the security situation in Afghanistan remains precarious,” said Obama, who was flanked by Defense Secretary Ash Carter and Gen. Joseph Dunford, chairman of the Joint Chiefs of Staff.

“Even as they improve, Afghan security forces are still not as strong as they need to be," he added.

The president arrived at the number 8,400 after learning lessons from the past two fighting seasons, a senior administration official told reporters in a conference call immediately after Obama’s remarks.

Wednesday’s announcement marks the latest official prolongment of the nearly 15-year war that Obama promised to end in his early days in office. Although Obama heeded the military’s requests for a troop surge in the early years of his presidency, he has said consistently that he would end the war before leaving office. But advances by the Taliban have prompted Obama to repeatedly extend his self-imposed deadlines for pulling troops out of Afghanistan.

Obama vowed in May 2014 to end combat operations by the end of the year, leave 9,800 residual troops in Afghanistan through 2015, cut that number in half in 2016, and have only a small presence to guard the U.S. embassy by the end of this year.

Although Obama announced an end to the U.S. combat mission in Afghanistan in December 2014, the statement appeared largely ceremonial as troops were still authorized to conduct dangerous counterterrorism missions. Indeed, 38 American military personnel and civilians have been killed in Afghanistan in the last year-and-a-half, Obama said Wednesday.

After the Taliban drove Afghan forces from the city of Kunduz last year, Obama readjusted his timetable, announcing plans to keep the nearly 10,000 troops in Afghanistan through most of 2016, and leave 5,500 troops into 2017.

Obama said Wednesday that his decision to keep a larger troop presence in Afghanistan through 2017 was partially motivated by a desire to give his successor more “flexibility.” Presumptive Democratic presidential nominee Hillary Clinton has in the past backed the president’s decision to leave a small contingent of troops in Afghanistan in an advisory role to support and train the local forces. Donald Trump, the presumptive Republican nominee, has said that invading Afghanistan was a mistake, but that troops should remain in the country.

"My decision today also sends a message to the Taliban and all those who have opposed Afghanistan’s progress,” Obama said, adding that a full drawdown of foreign forces from Afghanistan can only happen if the Afghan government and the Taliban reach a negotiated reconciliation. “You have now been waging war against the Afghan people for many years," he said. "You have been unable to prevail. Afghan security forces continue to grow stronger, and the commitment of the international community, including the United States, to Afghanistan and its people will endure.”