President Joe Biden, having concluded there is no military solution to the security and political problems plaguing Afghanistan and determined to focus on more pressing national security challenges, will formally announce Wednesday that US troops will withdraw from the country before the 20th anniversary of the September 11 terror attacks, a senior administration official said.

The withdrawal extends the US troop presence past a May 1 deadline set by the Trump administration in an agreement with the Taliban, but only by a matter of months.

Biden has been weighing the decision for months with his advisers and signaled he did not believe US troops should remain in the country long past the deadline.

The senior administration official said NATO troops would also follow the same withdrawal timeline. It’s possible US troops will be withdrawn “well before” September 11, the official said, saying the date was the last possible time when remaining personnel would leave.

The official said the US had communicated to the Taliban “in no uncertain terms” that attacks on US troops during the withdrawal process would be met with retaliation.

But the withdrawal of US forces comes with risks, as Biden’s last two predecessors, Presidents Barack Obama and Donald Trump, tried but were ultimately unable to untangle the US from the war in Afghanistan.

Senior military commanders have advocated keeping US troops in the country and have argued that a premature withdrawal could lead to a collapse of the Afghan government. A US intelligence community assessment released Tuesday warned that the Taliban was likely to make gains on the battlefield.

In discussions over the past month, Biden was “adamant” that a hasty withdrawal was not viable. But he judged that remaining in the country much longer did not reflect the needs of the current global threat picture. Biden asked for a policy review that would include “genuine realistic options” that would not “sugar-coat” that situation.

The official said that unlike past efforts to set a US withdrawal date, Biden’s deadline was not conditions-based.

“The President has judged that a conditions-based approach, which is then the approach of the past two decades, is a recipe for staying in Afghanistan forever. And so he has reached the conclusion that the United States will complete its drawdown, will remove its forces from Afghanistan before September 11,” the senior official said.

US officials say there are about 2,500 troops in Afghanistan. The US isn’t planning to withdraw completely, as the senior administration official said some troops will remain in the country to provide diplomatic security, though the exact number had not yet been decided.

In addition, it’s not immediately clear what will happen to several hundred US special operations forces there that often work for the CIA on counter terrorism missions. Those troops are not publicly acknowledged and are not part of the formal calculation of 2,500 troops in the country.

Biden’s decision split Capitol Hill, with Republican hawks slamming the withdrawal plans as a “grave mistake.” Congressional Democrats, meanwhile — along with a handful of Republicans — praised Biden for finally bringing an end to the US war.