General David Petraeus, former commander of NATO troops in Afghanistan, has retired after a career of 37 years in the US military.
He will take over as head of the CIA next week.
The general oversaw troop surges in Iraq and Afghanistan and was an early supporter of the military's shift to counterinsurgency tactics.
At a farewell ceremony, General Petraeus, 58, warned lawmakers not to cut the military's budget too sharply.
''As our nation contemplates difficult budget decisions, I know that our leaders will remember that our people, our men and women in uniform are our military," he said, adding that ''taking care of them and their families must be our paramount objective.''
General Petraeus also warned it was important to maintain the ''versatility and flexibility'' developed during the past decade of counter-insurgency conflicts.