WASHINGTON (AP) — President Barack Obama will seek to keep 9,800 U.S. troops in Afghanistan after the war formally ends later this year and then withdraw most of those forces by 2016, senior U.S. administration officials said Tuesday.

Obama's decision is largely in line with what military commanders have been seeking and would allow the president to fully end the American-led military effort by the time he leaves office.

The two-year plan is contingent on the Afghan government signing a bilateral security agreement with the U.S. While outgoing Afghan President Hamid Karzai has declined to sign the agreement, U.S. officials are confident that either of the candidates seeking to replace him would give his approval.

The plan calls for the U.S. military to draw down from its current force of 32,000 to 9,800 by the start of next year. Those remaining troops would be throughout Afghanistan.

Over the course of next year, the number of troops would be cut in half and consolidated in the capital of Kabul and at Bagram Air Field, the main U.S. base in Afghanistan. Those remaining forces would largely be withdrawn by the end of 2016, with fewer than 1,000 remaining behind to staff a security office in Kabul.

Obama is to announce the plan from the White House Tuesday afternoon. He is just back from a surprise weekend trip to Afghanistan where he met with U.S. commanders and American forces serving in the closing months of the nation's longest war.

The officials providing details of the announcement insisted on anonymity because they were not authorized to discuss the plan by name ahead of the president.

Ahead of his remarks, Obama was expected to speak with Karzai, who has had a tumultuous relationship with the White House. The two leaders did not see each other while Obama was in Afghanistan, but they did speak by phone as Air Force One was returning to Washington.

Obama has also discussed his plans with several European leaders, including German Chancellor Angela Merkel, British Prime Minister David Cameron and Italian Prime Minister Matteo Renzi.