(CNN) -- Sgt. Bowe Bergdahl pleaded guilty to desertion and misbehavior before the enemy via his attorney Monday. Bergdahl was charged after he disappeared from his base in Afghanistan in June 2009 and was held in captivity by the Taliban until May 2014. The Taliban released Bergdahl in a prisoner swap for five detainees at Guantanamo Bay. During questioning from a judge, Bergdahl said Monday, "I left my observation post on my own." He also said, "I understand leaving was against the law."