Ending his surprise visit to Afghanistan to meet with President Hamid Karzai , President Obama addressed troops at Bagram Air Force Base thanking them for their service and pledging his unwavering support .