The United States military will remain in Afghanistan until September, with the option of launching airstrikes against the Taliban to defend Afghan forces, according to U.S. officials on Thursday, even as the last combat troops prepare to leave the country in the coming days.

For weeks, officials have said that the main US military force and its equipment would be largely removed from Afghanistan by this weekend, well ahead of President Joe Biden’s Sept. 11 deadline. Army Gen. Scott Miller, the top US commander there, would then depart, signaling a significant shift in the US mission. However, a number of complicating factors mean that America’s involvement in the 20-year war will continue.

Officials said that when Miller departs, his combat role, including authority to conduct strikes on the Taliban and counter-terrorism operations against al-Qaida or other groups, will be assumed by Marine Gen. Frank McKenzie, the top US commander for the Middle East, who is based in Florida. Officials said the United States has conducted several airstrikes in support of the Afghans in recent weeks, using warplanes based outside of Afghanistan, and that these operations will continue.

Navy Rear Adm. Peter Vasely, who will lead the security mission at the US Embassy, will be the new US commander inside Afghanistan. He is already in Kabul, working with Miller on a transition, according to the officials, who spoke on the condition of anonymity to discuss new details of the withdrawal.

Vasely will have 650 US troops in the country, primarily at the embassy to secure the diplomatic mission, and this force will remain in place indefinitely. Furthermore, McKenzie will have the authority to keep up to 300 more troops in Afghanistan until September to help with security, including at the airport, according to officials.

The Pentagon and other US leaders, from the White House to Capitol Hill, have expressed concern about a recent increase in violence in Afghanistan, fearing that it will lead to a widespread civil war and the collapse of the Afghan government and military.

Miller painted a bleak picture of the security situation during his final press conference in Kabul earlier this week. He lamented the Taliban’s rapid takeover of districts across the country, warning that “a civil war is certainly a path that can be visualized if this continues on the trajectory it’s on right now, and that should be of concern to the world.” Meanwhile, the United States is scrambling to devise a strategy to get some of the thousands of Afghan interpreters and others who assisted the US-led coalition out of the country. While the US military is not expected to play a significant role in the evacuation, troops may be required to ensure the security of the departures.

As a result, while the military has accelerated its departure, security necessitates that the September deadline remain the ultimate goal.

Officials have repeatedly stated that security at Kabul’s Hamid Karzai International Airport is a critical requirement for the continued presence of US diplomatic personnel in Afghanistan. While Turkey has agreed to continue the mission, agreements with Afghanistan and the United States have yet to be finalized.

This withdrawal effectively fulfills an agreement reached when the Trump administration signed a peace treaty with the Taliban in February 2020. The agreement called for the withdrawal of US forces by May 2021, in exchange for the Taliban promising to cut ties with al-Qaida and ensure that Afghanistan did not become a safe haven for militants seeking to attack the US. Biden extended the withdrawal deadline to September 11 after taking office.

The United States has also stated that it will continue to monitor terror organizations operating in Afghanistan, including al-Qaida and the Islamic State group. Furthermore, the United States retains the authority to strike any militants who pose a threat to the American homeland.

Bagram Airfield, a massive complex north of Kabul that has long served as the hub of American military power in Afghanistan, is set to be handed over to the Afghans at any time.

NATO agreed to withdraw its roughly 7,000 non-American forces in April, and as of this week, 19 nations had announced troop withdrawals totaling over 4,800. Germany and Italy declared their missions in Afghanistan over on Wednesday and Poland’s last troops have returned home.