WASHINGTON - A top Army commander Monday unexpectedly ordered Sgt. Bowe Bergdahl, who was held captive for five years by the Taliban, to face a court-martial on charges of desertion and endangering other troops for walking off his combat outpost in eastern Afghanistan in 2009.

Bergdahl's trial could begin by May, two years after he was handed over to U.S. forces in a swap approved by the White House for five Taliban prisoners from the military prison at Guantánamo Bay, Cuba.

The decision by Gen. Robert B. Abrams, commander of Army Forces Command at Fort Bragg, N.C., was the latest twist in a case that has been divisive in the military and a partisan issue in Congress and the 2016 presidential campaign.

Abrams' order came as a surprise because the Army lawyer who presided over a preliminary hearing in San Antonio, Texas, in September recommended that Bergdahl face a lower-level court-martial reserved for misdemeanor offenses in the military justice system, and that he be spared any jail time.

In a statement, Abrams did not explain why he was pressing far more serious charges. Under military law, he is the convening authority who decides whether evidence warrants a court-martial.

The charges are severe enough that Bergdahl could face a maximum sentence of life imprisonment if he is convicted.

Some Pentagon and Obama administration officials argued that Bergdahl suffered enough during his Taliban captivity, while critics in Congress and the Army said an aggressive prosecution was needed to demonstrate the seriousness of desertion.

Eugene R. Fidell, Bergdahl's civilian lawyer, said in a statement that Abrams "did not follow the advice of the preliminary hearing officer who heard the witnesses."

Bergdahl was a private when he walked off Observation Post Mest in Paktika Province on June 30, 2009. Over the next few months, commanders ordered numerous search parties in rugged territory laced with Taliban fighters.

Taliban militants quickly captured Bergdahl and transferred him to the militant Haqqani network, who moved him to strongholds in Pakistan. He was repeatedly tortured, kept in the dark, and held in solitary confinement for much of the next five years, officials have said.

During the preliminary hearing, an expert who had debriefed Bergdahl described conditions of his captivity as the worst endured by any U.S. soldier since the Vietnam War.

He was freed in May 2014 after President Obama agreed to swap him for five senior Taliban prisoners, who were moved to supervised watch in Qatar. At the time, Obama said he had acted to get the only U.S. military prisoner of war back from the enemy.

Bergdahl, who is from Hailey, Idaho, is assigned to a desk job at Joint Base San Antonio.

He avoided public comment until last week, when he told the podcast Serial that he left his base to catch the attention of military commanders, and to alert them to what he said was "leadership failure" in his unit.

Maj. Gen. Kenneth Dahl, who was charged with investigating Bergdahl's conduct, testified at the preliminary hearing that Bergdahl was "young, naive, and inexperienced" when he walked off the base, and was "truthful" and "remorseful" about endangering U.S. soldiers who searched for him.