KABUL, AFGHANISTAN - Inside the heavily secured headquarters of the NATO-led forces in Kabul, the man who could be the last commander of America's longest war will officially take charge on Sunday of U.S. and NATO forces in Afghanistan.

Marine Gen. Joseph Dunford will replace Marine Gen. John Allen, who is expected to become NATO's supreme allied commander in Europe.

With the United States committed to removing its combat troops from Afghanistan by the end of 2014, Dunford's assignment will include winding down a U.S. presence that stretches back to just after the Sept. 11, 2001, terrorist attacks. Already, the number of American bases is shrinking, and the U.S. involvement in combat, as shown by the number of dead and wounded, is dropping. Several countries that have fought side by side with the United States already have withdrawn their forces or intend to soon.

The United States and its allies have said they'll leave some troops behind to train and support Afghan security forces, but Dunford's command marks the beginning of the end of America's war in Afghanistan.

It's unlikely to be a smooth glide to the exit, and Dunford acknowledged that during his Senate confirmation hearing.

"I recognize that much work needs to be done and the challenges will be many," he said. "But with continued focus and commitment, I believe our goals are achievable."

Statesman and commander

Dunford holds a pair of master's degrees, one in government from Georgetown University and another in international relations from Tufts University. Those can only help in a role as much statesman as commander. But his calm approach and diplomatic skills will inevitably be tested by Afghan President Hamid Karzai, a sometimes prickly and unpredictable ally.

Among the problems Dunford inherits are helping to train and support an Afghan force that has little in the way of a supply chain and no significant air support of its own. There are other simmering issues with Karzai, such as control over detainees.

Also critical is providing proper support for the pivotal presidential election scheduled for April 2014. That vote would give the country its first president who is not Karzai since the 2001 U.S.-led invasion. Among Afghans and the international donors that account for nearly all of the nation's economy, the success of that election is widely seen as a bellwether of the nation's future.

And then there is the actual war. The Taliban has been hit hard since a U.S. troop surge in 2010. U.S. casualties are at their lowest point in years, but that is at least partly a reflection of Afghan units taking the lead more often, and Afghan casualties have been rising.

U.S. leaders say that among the positive things Dunford inherits are a marked improvement recently in the abilities of the Afghan troops. That allowed Obama to say last month that Afghan forces will take the lead sooner than expected, and that by spring they will do so across the country. Coalition forces including U.S. troops would still be fighting beside the Afghans, he said, "but in a training, assisting, advising role."

Meanwhile, so-called green-on-blue incidents in which Afghan soldiers attack their NATO allies remain a serious threat, though measures instituted under Allen to reduce them seem to have had an effect.

Buildup and drawdown

Afghan forces have almost reached their troop-strength goal of 352,000. About 66,000 U.S. troops remain, down from the surge peak of about 100,000.

The timetable for reducing the size of that force is still unclear. Also, Obama has yet to announce a decision on how many -- if any -- will remain after 2014. None will, he said last month, if the Afghans won't agree to give them immunity from prosecution, which has been an issue in discussions with Afghan leaders over U.S. troop levels and has killed the possibility of any U.S. troops remaining in Iraq. Any who do remain in Afghanistan would have only limited roles with training and counterterrorism missions.

The job Dunford is taking has been both difficult and star-crossed. Army Gen. David McKiernan was fired, and Army Gen. Stanley McChrystal resigned after a Rolling Stone magazine article in which comments attributed to McChrystal and his staff undercut Obama and other senior civilian leaders. And Allen's nomination for the NATO command in Europe was held up when his named was briefly tied to an infidelity scandal that ended David Petraeus' career as CIA director. Petraeus also had been the U.S. commander in Afghanistan.