President Barack Obama gave up Wednesday on ending the war in Afghanistan during his term in office and said that at least 8.400 U.S. troops will still be on the ground for the next occupant of the White House to command.

With the Taliban resurgent under a new leader, and the Afghan army struggling to make headway, Obama bowed to the recommendations of his generals to shore up the Kabul government with a continuing U.S. and NATO presence along with billions in additional funding.

“I strongly believe that it is in our national security interest, especially after all the blood and treasure we’ve invested in Afghanistan over the years, that we give our Afghan partners the very best opportunity to succeed,” Obama said.

To that end, “Instead of going down to 5,500 troops by the end of this year” from the current authorized level of 9,800, “the United States will maintain approximately 8,400 troops in Afghanistan into next year, through the end of my administration,” Obama said.

Obama said his action would enable “my successor to make future decisions about our presence in Afghanistan. The decision I’m making today ensures that my successor has a solid foundation for continued progress in Afghanistan as well as the flexibility to address the threat of terrorism as it evolves.”

Obama made the announcement in the Roosevelt Room of the White House, where he was flanked by Defense Secretary Ashton Carter and Joint Chiefs Chairman Gen. Joseph Dunford.

In a later statement, Carter said that keeping 8,400 troops in Afghanistan “will enhance our ability to continue progress on our two central missions in Afghanistan -- strengthening Afghan forces so they can secure their nation and prevent its use as a safe haven for terrorists.”

Obama, often accused by Republicans of ignoring the advice of military leaders, said he was keeping 8,400 troops in Afghanistan mainly based on the recommendations and assessments of Army Gen. John Nicholson, who succeeded Army Gen. John Campbell as U.S. and NATO commander in Afghanistan in March. Nicholson’s report through the chain of command was endorsed by Carter, Dunford and Army Gen. Joseph Votel, commander of U.S. Central Command, Obama said.

Nicholson, with long experience in Afghanistan during previous tours, arrived there in March pledging to do a 90-day review and give his frank military judgment to the chain of command on whether Obama’s existing withdrawal plan was viable.

Obama had been committed to reducing the number of U.S. troops to 5,500 by the end of this year, and then to what would have been an embassy presence in 2017. Obama backed off the initial plan earlier this year, agreeing to keep 9,800 troops in Afghanistan through the rest of this year, but the U.S. presence in 2017 was an unknown until Wednesday and the White House announcement.

Obama entered office in 2008 with a commitment to ending the wars in Iraq and Afghanistan. He withdrew all U.S. troops from Iraq in 2011, only to have to send thousands back beginning in 2014 as the Islamic state of Iraq and Syria overran large swaths of the country.

In 2010, acting on the advice of the generals, Obama ordered a “troop surge” in Afghanistan, bringing the U.S. troop presence on the ground to more than 100,000, but he also said that they would begin withdrawing after two years. In 2014, the U.S. and NATO turned over the lead combat role in Afghanistan to local forces, and troop withdrawals accelerated in 2015.

In a statement, Afghan President Ashraf Ghani welcomed Obama’s announcement, which signaled an extension of crucial support at a time when militant attacks have the weakness of local forces.

“The decision is a sign of continued partnership between our nations to fight our common enemy and strengthen regional stability,” Ghani said through his spokesman, Haroon Chakhansuri.

Taliban spokesman Zabiullah Mujahid said the United States had been unable to defeat the group with a force of 100,000 and would fail to do so with a smaller footprint. “However long American invading forces remain in Afghanistan, their defeat will be definite,” he said in a statement.

The details of the continued U.S. and NATO presence in Afghanistan were expected to be fleshed out at the NATO summit in Warsaw this weekend, which will be attended by Obama, Ghani and Afghan Chief Executive Abdullah Abdullah.

NATO has already committed to an additional $5 billion in funding through 2020 for the Afghan National Defense and Security Forces.

-- Richard Sisk can be reached at Richard.Sisk@Military.com.