Secretary of Defense Ashton Carter listens as U.S. President Barack Obama delivers a statement (Win McNamee/Getty Images)

The U.S. will slow its troop drawdown in Afghanistan, leaving a force of 8,400 when President Barack Obama completes his term, the president announced Wednesday in a blunt acknowledgment that America will remain entangled there despite his aspirations to end the war.

Flanked by top military leaders at the White House, Obama said the security situation in Afghanistan is "precarious" and the Taliban remain a threat roughly 15 years after the U.S. invaded in the aftermath of 9/11. He said he was committed not to allow any group to use Afghanistan "as a safe haven for terrorists to attack our nation again."

"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.

There are currently about 9,800 troops in Afghanistan, and Obama had planned to pull that back to 5,500 by year-end. But a Taliban resurgence and the Afghan military's continuing struggles have led the White House to rethink its exit strategy.

The numbers reflect a compromise between Obama's original plan and what many military commanders had urged.

Top military leaders had wanted the White House to stay closer to the current 9,800 there when he leaves office. Last month, a group of more than a dozen former U.S. ambassadors and commanders in Afghanistan publicly urged him to "freeze" the current level for the rest of his term and let the next president make any adjustments.

Obama appeared to settle on a number that would show continued progress toward drawing down without jeopardizing the mission.

Though U.S. officials said Obama was acting on a formal Pentagon recommendation of 8,400 troops, in recent weeks there were ongoing talks between the White House and the Pentagon, suggesting the final figure was the result of those discussions.

Obama's announcement comes with major implications for his legacy. He came into office promising to end the wars in Afghanistan and Iraq, but he'll leave with the U.S. still enmeshed in conflicts in both of those countries while wrestling with new ones in Syria and Libya.

Afghan President Ashraf Ghani welcomed Obama's decision. In Kabul, spokesman Haroon Chankhansuri called the decision "a sign of continued partnership between our nations to fight our common enemy and strengthen regional stability."

The president said the U.S. mission would remain narrowly focused on "training and advising" Afghan forces and supporting counterterrorism operations against the remnants of al-Qaida, the group that attacked the U.S. on Sept. 11.

"We are no longer engaged in a major ground war in Afghanistan," he said. At the peak, in 2010, U.S. troop levels surged to 100,000.

Republican leaders in Congress who favor a larger force said Obama's new plan was preferable to the old one, but they criticized him for not keeping the full 9,800. Sen. Lindsey Graham, R-S.C., said the partial drawdown would increase the dangers for the remaining troops, calling it "more a political decision by President Obama than a military one."

"President Obama's announcement today is a belated recognition that the war in Afghanistan has not yet been won," added House Speaker Paul Ryan, R-Wis.

As the military has prepared for the planned drawdown, it has become clear that keeping just 5,500 troops might not be logistically feasible.

Gen. John F. Campbell, the top U.S. commander in Afghanistan until March, warned Congress earlier this year that reducing the number too sharply would make it tougher to train Afghan forces and perform counterterror operations at the same time. The military was also concerned that it would need more than 5,500 to provide security and logistics support for allies fighting alongside the U.S.

Though Obama touted progress in Afghanistan, including better-trained security forces, the situation remains perilous, with Afghan battlefield deaths rising and civilian casualties hitting a record high. Just last month the Pentagon said in a report to Congress that Afghans were feeling less secure than at any other recent time. Obama pointed out that 38 Americans had died in the past 18 months.

Progress in stabilizing Afghanistan has been undermined by the regrowth of the Taliban, which were removed from power in the 2001 U.S.-led invasion but have lately stepped up their deadly attacks. After a long debate, the White House last month gave the military expanded authority to conduct airstrikes against the Taliban even though Obama declared the U.S. combat mission in Afghanistan over in 2014.

Ghani's efforts to get the Taliban to engage in peace talks have been mostly fruitless, and the Afghan public has started losing patience as security worsens. Still, the Obama administration said it still supports a political settlement that would let the Taliban play a role in Afghanistan's future, as long as they renounce violence.

Obama has been under pressure from NATO allies and U.S. lawmakers to make a decision before he attends a NATO summit later this week in Warsaw, Poland. Last month, the alliance announced it would maintain troops in regional locations around Afghanistan.

Obama said boosting the planned troop levels would help other countries prepare their own contribution to the fight. He said his decision should help the next president make good decisions about the future of U.S. involvement.

"l firmly believe the decision I'm announcing is the right thing to do," Obama said.

Sign up for the NJ1015.com Newsletter

Get the best of NJ1015.com delivered to your inbox every day.

(Copyright 2016 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed)