WASHINGTON (AFP) - United States President Joe Biden's pullout from Afghanistan has stunned with its speed, but Washington already decided four years ago that it was fed up with "forever wars" and turned its attention to traditional great power competition with China and Russia.
Fighting stateless terror groups like Al-Qaeda and Islamic State consumed the US security establishment, and trillions of dollars, since the Sept 11, 2001, attacks.
Mr Biden's predecessor Donald Trump came to office in 2017 promising to quit Afghanistan, calling the war there a "mess" and a "waste". The conflicts there and in Iraq had come to be characterised by unending troop deployments, persistent levels of violence and no ability to conclusively defeat the enemy.
By 2020, Mr Trump had overcome resistance and laid the ground for pullouts, leaving only 2,500 troops in each country by the time he stepped down in January. Mr Biden accepted that trajectory, announcing on Thursday that US military involvement in Afghanistan would conclude by Aug 31.
"We are ending America's longest war," he said. "The United States cannot afford to remain tethered to policies created to respond to a world as it was 20 years ago."
The 9/11 attacks blindsided the US security establishment, forcing a whole-of-government refocus and the launching of the "war on terror". The US and Nato allies invaded Afghanistan to oust the Taleban government, which had protected Al-Qaeda.
And then President George W. Bush took advantage to also invade Iraq to overthrow strongman Saddam Hussein, hoping to remake the Middle East and snuff out a broader threat.
The initial assaults largely succeeded quickly, with Al-Qaeda fractured and on the run in Afghanistan, and Saddam deposed and captured in Iraq.
But in both cases, the US and allies remained on the ground, hoping to rebuild each country, and unable to pull out without risking a return to the pre-9/11 situation.
Then, starting in 2013, US security leaders rebooted their views when new Chinese President Xi Jinping began aggressively expanding his country's military.
Seeking to counter and surpass US military strength, China began building armed bases on disputed islets in the South China Sea, added a base in Djibouti and planned other bases around Asia and the Middle East.
Meanwhile in 2014, Russian President Vladimir Putin sent forces to seize Ukraine's Crimea and supported an insurgency in eastern Ukraine.
Two years later, Moscow mustered an aggressive campaign to influence the US presidential elections.
During the same period, young North Korean leader Kim Jong Un embarked on an ambitious plan to develop nuclear weapons with missiles that could threaten the US.
Mr Trump's 2017 National Security Strategy confirmed the pivot.
"China and Russia challenge American power, influence and interests, attempting to erode American security and prosperity," it said.
"They are determined to make economies less free and less fair, to grow their militaries, and to control information and data to repress their societies and expand their influence."
Reminiscent of the Cold War, the reorientation meant a Pentagon push to expand its navy, build stronger long-range bomber and submarine strike forces, and update its nuclear weapons.
It has also meant countering the Chinese and Russian challenge in new domains, with the Pentagon establishing both Space Command and Cyber Command.
The new priorities took root under Mr Trump, and Mr Biden confirmed them in March in his own national security policy.
"The distribution of power across the world is changing, creating new threats. China, in particular, has rapidly become more assertive," it said.
"Both Beijing and Moscow have invested heavily in efforts meant to check US strengths and prevent us from defending our interests and allies around the world."
Instead of Afghanistan and Iraq-Syria, Ukraine and Taiwan are the new flashpoints. Both have recently received more and more advanced US weaponry to deter, respectively, Russia and China.
The Pentagon created a new office focused on China. US naval vessels regularly sail the waters around Taiwan and in the South China Sea, implicitly challenging China's territorial claims.
As for Russia, Mr Biden has sought to strengthen bonds with Nato allies.
Over the past week, too, US vessels took part in exercises in the Black Sea where Russian forces were conducting their own manoeuvres.
Counterterrorism does not end with the Afghanistan pullout, the Pentagon stresses.
But it is turning more remote-directed - using air and missile strikes from remote bases and vessels to act in Afghanistan where Al-Qaeda still operates.
"We are repositioning our resources and adapting our counterterrorism posture to meet the threats where they are now," Mr Biden said.